
-----------------------------------
beard0
Fri Sep 30, 2005 7:46 pm

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....

-----------------------------------
Hikaru79
Fri Sep 30, 2005 8:05 pm


-----------------------------------
Is this program supposed to play against the player, or only offer two-player hotseat support? What feature are mandatory?

-----------------------------------
beard0
Fri Sep 30, 2005 8:18 pm


-----------------------------------
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
Mon Oct 03, 2005 5:56 pm


-----------------------------------
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 :P

-----------------------------------
beard0
Mon Oct 03, 2005 6:46 pm


-----------------------------------
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
Mon Oct 03, 2005 7:32 pm


-----------------------------------
i havent really tested it but... 20 lines:

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
Tue Oct 04, 2005 7:25 am


-----------------------------------
Pretty short code.   :o 

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
Tue Oct 04, 2005 8:51 am


-----------------------------------
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.

-----------------------------------
zylum
Thu Oct 06, 2005 5:17 pm


-----------------------------------
lol, is no one even going to attempt to beat my submission???

-----------------------------------
Naveg
Sun Oct 09, 2005 9:17 am


-----------------------------------
theres only supposed to be 7 columns......

-----------------------------------
zylum
Sun Oct 09, 2005 12:03 pm


-----------------------------------
lol, are you sure??? oops  :oops:

how many rows then? i fixed it so now its 7x7.

-----------------------------------
jamonathin
Fri Oct 14, 2005 8:30 pm


-----------------------------------
Zylum, can i ask you a question.

What the **** does . .

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. :?

-----------------------------------
[Gandalf]
Fri Oct 14, 2005 8:45 pm


-----------------------------------
Something to do with recursion, but those variable names are meant for shortness, not readability :|  n? c?

-----------------------------------
zylum
Sat Oct 15, 2005 10:32 pm


-----------------------------------
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 ;)

-----------------------------------
jamonathin
Sun Oct 16, 2005 1:33 pm


-----------------------------------

to get a better understanding of what i am doing there, you can read my bitwise operators tutorial ;)
I somewhat understand it, but ima need to look at that tut again.  :?

-----------------------------------
beard0
Wed Oct 26, 2005 8:15 pm


-----------------------------------
Well, unfortunately, zylum was the only submitter.  He wins by default.  He gets his 50 bits and gets to enjoy walking around compsci with his uber-mod style bits.  Unfortunately, he just can't brag about it, because the moment he does, they're gone.  Too bad.

-----------------------------------
Mr. T
Fri Oct 28, 2005 8:49 pm

Alex's Opinion
-----------------------------------
if not Sys.Exec ("C:/Turing/connect4.t") then
    put "Your computer must have viruses."
    put "Error: ", Error.LastMsg
end if
For the win!  8)

-----------------------------------
Cervantes
Sun Oct 30, 2005 8:52 am


-----------------------------------
Since when can you Sys.Exec a .t file?

-----------------------------------
Mr. T
Sun Oct 30, 2005 12:44 pm

Alex's Opinion
-----------------------------------
Shh, don't pop up my delusional bubble of self satisfaction. :cry:

-----------------------------------
beard0
Sun Oct 30, 2005 3:50 pm


-----------------------------------
Since when can you Sys.Exec a .t file?
Ever since I installed Turing :D

It will open the file in the Turing editor, it just wont run it.
