Euphoria

Euphoria is a language that is higly readable, easy to pick up and understand and yet fairly powerful. Currently, Euphoria is supported in DOS, Windows, Linux, and FreeBSD environments. The language is rather simple to use and has decent internal support of necessary functions. It's an interpreted language, and you can't bind (not compile) your file to the interpreter unless you pay for the registered version. Euphoria has a growing user base that contributes quite a lot to it. There are libraries for game engines, schedulers, system functions, graphics, sound, and linking to .dll files and even a library contributed that allows you to insert assembler right into your program to be assembled and run on the fly. The standard Eu libraries contain graphics, internal speaker sound, database management, sorting, keyboard support, console and file output, and machine functions. Euphoria allows you to get down into the hardware when you want to, but is at a high-enough level that you can ignore system architecture when designing a program. The four basic data types are: atom (like a float), integer (like an integer of course), sequence (a linked list, but has internal support so you don't have to call special functions to manipulate it), and an object, which can be any of the others. The site is http://www.rapideuphoria.com . Here's a link to all the documentation you could possibly want on Euphoria: http://www.rapideuphoria.com/doc.htm . For beginners to Euphoria and beginners to programming, the Beginner's Guide To Euphoria is excellent.

Example code

This is a small text-based tic-tac-toe game that i wrote as a challenge on my gaming forum. I threw it together in about 20 minutes, so the code's not all that great and there's no computer player, but hey, it works. If you have the ex.exe program and the get.e library you can run this and play tic-tac-toe with someone. The grid that's displayed corresponds directly to the number pad on your keyboard.

include get.e

constant BLANK=0
constant X=1
constant O=2

sequence grid, temp
integer spot
grid=repeat(0,9) --make a set of BLANKS

function movefunc(integer spot, integer player)
if grid[spot]=BLANK then
        if player=1 then
                grid[spot]=X
        elsif player=2 then
                grid[spot]=O
        end if
        return 0
else
        return 1
end if
end function

procedure p1()
integer ret
position(23,1)
puts(1,"Player 1, you are X's, pick a location:\n")
temp=get(0)
spot=temp[2]
ret=movefunc(spot,1)
if ret!=0 then
        p1()
end if
end procedure

procedure p2()
integer ret
position(23,1)
puts(1,"Player 2, you are O's, pick a location:\n")
temp=get(0)
spot=temp[2]
ret=movefunc(spot,2)
if ret!=0 then
        p2()
end if
end procedure

function checkwin(integer player)
sequence win
if player=1 then
        win={X,X,X}
elsif player=2 then
        win={O,O,O}
end if
if equal(grid[1..3],win)
or equal(grid[4..6],win)
or equal(grid[7..9],win)
or equal({grid[1],grid[4],grid[7]},win)
or equal({grid[2],grid[5],grid[8]},win)
or equal({grid[3],grid[6],grid[9]},win)
or equal({grid[1],grid[5],grid[9]},win)
or equal({grid[3],grid[5],grid[7]},win) then
        return 1
else
        return 0
end if
end function

procedure update_game()
for i=1 to 9 do
        if i=1 then
                position(11,2)
        elsif i=2 then
                position(11,4)
        elsif i=3 then
                position(11,6)
        elsif i=4 then
                position(9,2)
        elsif i=5 then
                position(9,4)
        elsif i=6 then
                position(9,6)
        elsif i=7 then
                position(7,2)
        elsif i=8 then
                position(7,4)
        elsif i=9 then
                position(7,6)
        end if
        if grid[i]=BLANK then
                puts(1," ")
        elsif grid[i]=X then
                puts(1,"X")
        elsif grid[i]=O then
                puts(1,"O")
        end if
end for
end procedure

procedure make_grid()
clear_screen()
position(1,1)
puts(1,"The grid is numbered 1-9 as such:\n7 8 9\n4 5 6\n1 2 3\n\n")
puts(1,"-------\n| | | |\n-------\n| | | |\n-------\n| | | |\n-------")
update_game()
end procedure

procedure main()
integer go, x, key
go=1
while go=1 do
        if go=1 then
                p1()
                make_grid()
        end if
        x=checkwin(1)
        if x=1 then
                clear_screen()
                puts(1,"Player 1 wins!")
                go=0
        end if
        if not find(BLANK,grid) and go!=0 then
                clear_screen()
                puts(1,"Tie game!")
                go=0
        end if
        if go=1 then
                p2()
                make_grid()
        end if
        x=checkwin(2)
        if x=1 then
                clear_screen()
                puts(1,"Player 2 wins!")
                go=0
        end if
        if not find(BLANK,grid) and go!=0 then
                clear_screen()
                puts(1,"Tie game!")
                go=0
        end if
end while
key=wait_key()
clear_screen()
end procedure

make_grid()
main()


CategoryLanguage

EuphoriaLanguage (last edited 2008-07-09 05:47:45 by localhost)