Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Connect 4
Index -> Contests
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
beard0




PostPosted: Fri Sep 30, 2005 7:46 pm   Post subject: Connect 4

Who can make the shortest (by line count) connect four game in turing? Lines will be counted after proper formatting, as defined by, after F2 is hit. 50 bits to the winner if they ever get working....
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Fri Sep 30, 2005 8:05 pm   Post subject: (No subject)

Is this program supposed to play against the player, or only offer two-player hotseat support? What feature are mandatory?
beard0




PostPosted: Fri Sep 30, 2005 8:18 pm   Post subject: (No subject)

It must obey the rules of connect four, on a standard size board, and have at least one human player - the second may be human or computer. Go for it any way you can! :)
md




PostPosted: Mon Oct 03, 2005 5:56 pm   Post subject: (No subject)

Why must it be limited to turing? Why can't we write it in whatever language we want... then just declare a winner for each language... I'd say just an overall winner, but as you don't technically need to put line breaks in some languages... perhaps character count would be better Razz
beard0




PostPosted: Mon Oct 03, 2005 6:46 pm   Post subject: (No subject)

Okay, opening it up to other languages, but it'll make me have to introduce more criteria. There will still be a winner for turing, as per the guidlines above. There will also be another winner for any language, who will win based on the shortness/elegance of the code, as judged by me, or any other judges I decide upon.
zylum




PostPosted: Mon Oct 03, 2005 7:32 pm   Post subject: (No subject)

i havent really tested it but... 20 lines:

code:
var data : array 1 .. 7, -1 .. 1 of int := init (0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
fcn winner (x, y, dx, dy, n, c : int) : boolean
    result ( ~ (x < 1| x > 7| y < 1| y > 7| (data (x, c) & (1 shl (y - 1))) = 0)) & (n = 3| winner (x + dx, y + dy, dx, dy, n + 1, c))
end winner
loop
    locate (1, 1)
    put "player ", (data (2, 0) + 1) div 2 + 1, " choose a column " ..
    get data (1, 0)
    data (data (1, 0), data (2, 0)) := (((data (data (1, 0), -1)| data (data (1, 0), 1)) shl 1 + 2) shr 1)| data (data (1, 0), data (2, 0))
    var flag := false
    for decreasing y : 7 .. 1
        for x : 1 .. 7
            put sign (data (x, -1) & (1 shl (y - 1))) + sign (data (x, 1) & (1 shl (y - 1))) * 2, " ", chr (ord ("\n") * (x div 7)) ..
            flag := flag| winner (x, y, 1, 0, 0, data (2, 0))| winner (x, y, 1, 1, 0, data (2, 0))| winner (x, y, 1, -1, 0, data (2, 0))| winner (x, y, 0, 1, 0, data (2, 0))
        end for
    end for
    exit when flag
    data (2, 0) *= -1
end loop
put "\nplayer ", (data (2, 0) + 1) div 2 + 1, " wins!"
codemage




PostPosted: Tue Oct 04, 2005 7:25 am   Post subject: (No subject)

Pretty short code. Surprised

In order to qualify for game of the century, it should probably check against putting pieces into an already full stack.

(Besides that - I'm not going to even bother trying to beat that in Turing).
beard0




PostPosted: Tue Oct 04, 2005 8:51 am   Post subject: (No subject)

codemage wrote:
it should probably check against putting pieces into an already full stack.


Good call. I did ask that it follow the rules of the game. Still, nice job zylum.
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Thu Oct 06, 2005 5:17 pm   Post subject: (No subject)

lol, is no one even going to attempt to beat my submission???
Naveg




PostPosted: Sun Oct 09, 2005 9:17 am   Post subject: (No subject)

theres only supposed to be 7 columns......
zylum




PostPosted: Sun Oct 09, 2005 12:03 pm   Post subject: (No subject)

lol, are you sure??? oops Embarassed

how many rows then? i fixed it so now its 7x7.
jamonathin




PostPosted: Fri Oct 14, 2005 8:30 pm   Post subject: (No subject)

Zylum, can i ask you a question.

What the **** does . .
code:

fcn winner (x, y, dx, dy, n, c : int) : boolean
    result ( ~ (x < 1| x > 7| y < 1| y > 7| (data (x, c) & (1 shl (y - 1))) = 0)) & (n = 3| winner (x + dx, y + dy, dx, dy, n + 1, c))
end winner

mean???!!

Im tryin to understand, and im stumped. Confused
[Gandalf]




PostPosted: Fri Oct 14, 2005 8:45 pm   Post subject: (No subject)

Something to do with recursion, but those variable names are meant for shortness, not readability Neutral n? c?
zylum




PostPosted: Sat Oct 15, 2005 10:32 pm   Post subject: (No subject)

code:
fcn winner (x, y, dx, dy, inARow, clr) : boolean
    if x < 1 or x > 7 or y < 1 or y > 7 or (data (x, clr) and (1 shl (y - 1))) = 0 then
        result false
    end if
    result n = 3 or winner (x + dx, y + dy, dx, dy, n + 1, c)
end winner


so the first conditional checks if the current grid position is in bounds and that it contains the proper colour. If not, result false (no winner). else, if n (the number of previous peices of the same color in a row) is equal to 3 then the current position is the fourth in a row and result true. if n doesnt equal to 3 then call winner again updating the x and y position. dx and dy are the direction we are checking.

to get a better understanding of what i am doing there, you can read my bitwise operators tutorial Wink
jamonathin




PostPosted: Sun Oct 16, 2005 1:33 pm   Post subject: (No subject)

zylum wrote:

to get a better understanding of what i am doing there, you can read my bitwise operators tutorial Wink

I somewhat understand it, but ima need to look at that tut again. Confused
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: