This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Luiginico's profile picture

Connect Four

Started by Luiginico, 20 March 2013 - 10:23 AM
Luiginico #1
Posted 20 March 2013 - 11:23 AM
Hi, it's me again, this time I made a little Connect Four.

To download use: Pastebin get u4FPcbqD c4

Features
  • Multiplayer
  • Uses the new modems API
  • Simple GUI
  • Auto-Win Detection
  • 100% Advanced computer compatible

To Do
  • Singleplayer mode (Still don't know how to code the AI)
  • Colours
  • Tutorial screen

Screenshots:
Spoiler



The code can be found here: http://pastebin.com/u4FPcbqD
Edited on 20 March 2013 - 10:30 AM
TheOddByte #2
Posted 20 March 2013 - 11:27 AM
So this is like tic tac toe?
Seems nice!
Now you should add some kind of single player with an AI..
Since that would be awesome too..
Luiginico #3
Posted 20 March 2013 - 11:34 AM
So this is like tic tac toe?
Seems nice!
Now you should add some kind of single player with an AI..
Since that would be awesome too..
Yes, it's like a tic tac toe with gravity.
I could make a singleplayer, but I have no idea how to make the AI
TheOddByte #4
Posted 20 March 2013 - 11:38 AM
So this is like tic tac toe?
Seems nice!
Now you should add some kind of single player with an AI..
Since that would be awesome too..
Yes, it's like a tic tac toe with gravity.
I could make a singleplayer, but I have no idea how to make the AI
Well it's not impossible but it's really difficult though..
Anyway, Great program!
Shnupbups #5
Posted 20 March 2013 - 11:42 AM
Want me to make a colour version of this with clicking?
Luiginico #6
Posted 21 March 2013 - 07:40 AM
Want me to make a colour version of this with clicking?
The code is up there for everybody, if you want to, go ahead :)/>
RustikGaming #7
Posted 24 March 2013 - 05:17 AM
Edit: nevermind just a derp by me
theoriginalbit #8
Posted 24 March 2013 - 05:25 AM
just an fyi the code for this program is broken with the new functionality of rednet channels and modems
Uhhh it is using the modems and channels…

EDIT: nvm, just saw your edit…
QuantumGrav #9
Posted 25 March 2013 - 06:56 PM
Really like this program, Good Job!

I'm working on some form of game playing intelligence on other games, so here's my two cents on how you could program the computer to play.

A basic strategy could pick a random number between 1 and the number of columns (8), then play in that column. It wouldn't play brilliantly, but it would play.

Slightly more advanced could be detecting if the player has three pieces in a row, then block it. You've got the board as a table, so check every square surrounding a player's piece in that table. If another player's piece is next to the original, continue on that axis, and, again, see if another of the player's pieces is there. If so, play in the column to block it. That is quite a bit harder to program, but entirely possible.

Another even more advanced strategy would assign values to certain configurations of pieces. For example, the computer would value having 4 of its pieces in a row as basically infinite. Having three in a row would have a positive value and so on and so forth. It would also analyze the opponent's configurations, and assign those negative values. Add those two numbers together and you have a quantifiable number for every position. The larger that number is, the better the position is for the computer. The computer would iterate through several or every possible scenario for two or so turns, analyze them all, and then pick the one with the largest number. That would be remarkably difficult, but again, entirely possible.

Sorry for being so wordy. Simply based on easiness, if your going to implement an AI, I would use the basic one. There also may be other, simpler ways to create an AI with some intelligence that I haven't thought of.

Again, I really like your program! Hope that helps somewhat!
martin509 #10
Posted 26 March 2013 - 08:21 AM
One question: Why use channels? It's two-player, so it's not like you need them. I run a tekkit server with my friends and really want to play this game, but tekkit has to be a light-year behind and use CC 1.3 or so.
Ristyo #11
Posted 27 March 2013 - 03:01 AM
There is a redstone computer map that plays connect four, and now there is the same without redstone
Luiginico #12
Posted 22 June 2013 - 09:36 AM
Wow, so many replyes, considering this is the simpler of my 3 games

One question: Why use channels? It's two-player, so it's not like you need them. I run a tekkit server with my friends and really want to play this game, but tekkit has to be a light-year behind and use CC 1.3 or so.
I never liked how rednet worked, a simple broadcast could destroy your entyre program, and, using channels you can play multiple istances of this game w/o problems

Really like this program, Good Job!
[…]
Again, I really like your program! Hope that helps somewhat!
Thanks :)/>

[…]
A basic strategy could pick a random number between 1 and the number of columns (8), then play in that column. It wouldn't play brilliantly, but it would play.
[…]
(The coloumns are 7), yeah, that was my original idea, but, it's like playng against a cat, but still an idea

[…]
Slightly more advanced could be detecting if the player has three pieces in a row, then block it. You've got the board as a table, so check every square surrounding a player's piece in that table. If another player's piece is next to the original, continue on that axis, and, again, see if another of the player's pieces is there. If so, play in the column to block it. That is quite a bit harder to program, but entirely possible.
[…]
I'm already using this method to detect if a player managed to win, so it wouldn't be hard to do

[…]
Another even more advanced strategy would assign values to certain configurations of pieces. For example, the computer would value having 4 of its pieces in a row as basically infinite. Having three in a row would have a positive value and so on and so forth. It would also analyze the opponent's configurations, and assign those negative values. Add those two numbers together and you have a quantifiable number for every position. The larger that number is, the better the position is for the computer. The computer would iterate through several or every possible scenario for two or so turns, analyze them all, and then pick the one with the largest number. That would be remarkably difficult, but again, entirely possible.
[…]
This, is gonna be hard, but, maybe, w/ some time I can come up w/ something, I will try.
H4X0RZ #13
Posted 22 June 2013 - 09:48 AM
I've found this ANN. you can use it for singleplayer (it's a learning artificial Neural Network) :D/>/>/>
Luiginico #14
Posted 22 June 2013 - 10:02 AM
I've found this ANN. you can use it for singleplayer (it's a learning artificial Neural Network) :D/>/>/>
I don't tink that a ANN is necessary, I think I can get the job done w/ some ifs
jwilman185 #15
Posted 22 June 2013 - 10:03 PM
I tried this but failed :(/> but well done :)/>
Nick0157 #16
Posted 25 June 2013 - 02:54 PM
Nice game! I'll have to add it to my computer with all my other games!