Liberty BASIC Community Forum
« Pure coding challenge - Connect 4 AI »

Welcome Guest. Please Login or Register.
Jun 25th, 2017, 12:21am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Pure coding challenge - Connect 4 AI  (Read 1967 times)
theblazingicicle
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 410
xx Pure coding challenge - Connect 4 AI
« Thread started on: May 20th, 2004, 04:47am »

Hia everyone smiley

Here is a new challenge:

Write an AI that can play (and win) connect 4.

The rules of Connect 4 are described here: http://www.ludoteka.com/connect4.html

The challenge is to write a function that is given a player number (1 or 2) and a board (which is an array), and can return a column into which to drop the next counter.

You can make the system as simple or as complicated as you like. wink

I have already written a 'framework' program that does all the boring bits of the interface and stuff. All you have to write is the AI function:
http://www.eccentrix.com/members/arro/wwwboard/55.html

You will notice that the function willwin has been removed, as I thought it would make the challenge too easy. If you need this function you will need to write your own.

Post entries (just the GetNextMoveAi function) at http://www.eccentrix.com/members/arro/wwwboard/55.html .

The closing date will be around 17th June.

If we have enough entries, I hope to run a tournament between the AIs in order to pronounce a winner.

I hope to see some really powerful AIs that will beat a human!

Good luck. wink

TBI
« Last Edit: May 20th, 2004, 04:49am by theblazingicicle » User IP Logged

Inaliable rights:
Life, liberty and the pursuit of BASIC
Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
xx Re: Pure coding challenge - Connect 4 AI
« Reply #1 on: May 20th, 2004, 06:29am »

This could be a lot of fun, TBI! I wrote a 2 player connect 4 game years ago (it was a multiplication table drill and practice disguised as a game) and rewrote it (minus the educational stuff) last fall when I first started LB programming. The program does successfully test for 4 in a row and declares a winner, but there's no computer play. 'Course that was before I knew about user-declared functions. I'm as much looking forward to what others contribute as I am to taking a crack at it myself. It's been awhile since the last contest. What a fun way to start up again! cheesy
Janet
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
theblazingicicle
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 410
xx Re: Pure coding challenge - Connect 4 AI
« Reply #2 on: May 20th, 2004, 06:34am »

Glad you think its a good idea, Janet.

Talking about user declared functions, I hope some people learn about the benefits of modular (using lots of functions) programming by doing this. Only by use of a function could we 'collaborate' like this easily on a program.
User IP Logged

Inaliable rights:
Life, liberty and the pursuit of BASIC
Alex L.
Guru
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1384
xx Re: Pure coding challenge - Connect 4 AI
« Reply #3 on: May 20th, 2004, 4:57pm »

on May 20th, 2004, 06:29am, Janet wrote:
This could be a lot of fun, TBI!

I completely agree!

PS: I am sorry to ask this but what does TBI mean!? In the acronym dictionary it says "Tunnel Base in Iraq", however taht doesn't really fit here...
User IP Logged

Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
xx Re: Pure coding challenge - Connect 4 AI
« Reply #4 on: May 20th, 2004, 5:14pm »

Quote:
PS: I am sorry to ask this but what does TBI mean!? In the acronym dictionary it says "Tunnel Base in Iraq", however taht doesn't really fit here...

Actually TBI means something much more eloquent than tunnel base in Iraq (there's an official acronym for that?? huh). It's a friendly way of saying TheBlazingIcicle.
Janet
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
Sean
Team Liberty BASIC


member is offline

Avatar

Linux and OS Enthusiast


PM

Gender: Male
Posts: 329
xx Re: Pure coding challenge - Connect 4 AI
« Reply #5 on: May 21st, 2004, 10:24am »

Quote:
(there's an official acronym for that?? )


Leave it to the govt. lol
wink

Sean
User IP Logged

Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
xx Re: Pure coding challenge - Connect 4 AI
« Reply #6 on: May 23rd, 2004, 3:30pm »

The rules keep getting in my way!! LOL. Let me just get this clarified. You don't want the whole program uploaded? You just want the function? But, can the "function" be a set of functions? Here's my dilemna: I have 4 functions.
1st: Check to see if computer can win, then drop in that column
2nd: Check to see if human can win, then block that column
3rd: Check to see if human can get an open ended 3 in a row across (e.g., 01110), and block that column
4th: Check to see if computer can get an open ended 3 in a row across and drop in that column
That's about all the strategy I can come up with. I didn't even attempt to program a "but don't put a marker in this column" function.
Do I have to somehow combine these 4 functions to just 1 function?
Janet

Janet

User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
theblazingicicle
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 410
xx Re: Pure coding challenge - Connect 4 AI
« Reply #7 on: May 24th, 2004, 09:35am »

Dont worry too much about the functions thing. I just wanted to make sure that it was possible to play the AIs against each other. The easiest way i could think to do that is by using these functions.
User IP Logged

Inaliable rights:
Life, liberty and the pursuit of BASIC
Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
xx Re: Pure coding challenge - Connect 4 AI
« Reply #8 on: May 24th, 2004, 9:42pm »

Okay, function posted. In my human vs computer game, the GetNextMoveAi(player) function opts for the computer win first (followed by blocking the human win), so I'll have to work on making a separate willWin(player) function. The real problem is that the ai strategy is only as good as the programmer's strategy and I'm not a very strategic player. undecided
Looking forward to seeing other entries.
Janet
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
kaboomer13
Senior Member
ImageImageImageImage


member is offline

Avatar

There are 10 types of people in this world: Those who know Binary and those who don't!


Homepage PM

Gender: Male
Posts: 404
xx Re: Pure coding challenge - Connect 4 AI
« Reply #9 on: May 26th, 2004, 10:30am »

Janet, I cannot manage to get your ai to work, I just wanted to see how you did it. (No worries I wont take your ideas). I couldn't manage to get it to work.

Could you take the code you submitted and then put it into the origional code that was given to all of us...

P.S. I did dimension your array(s)

thanks
User IP Logged

LBfully Yours,
Ben J Scott
Don't forget to check out DLL4LB!
Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
xx Re: Pure coding challenge - Connect 4 AI
« Reply #10 on: May 26th, 2004, 1:46pm »

Actually, I wrote a complete human vs computer game. Then, when I went to submit, I realized some of my variables needed name changing. I did a search and replace for changing my variable gameGrid to the contest variable board. It may be that there are still some incompatible variables. I'll look at it more closely over the weekend. In the meantime, if you'd like to look at the complete game, pm me and I'll email you the whole thing. I'm still working on expanding the function to include more steps before resorting to just choosing a random number, but, truthfully, the computer beats me about half the time.
Janet
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
theblazingicicle
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 410
xx Re: Pure coding challenge - Connect 4 AI
« Reply #11 on: May 27th, 2004, 03:17am »

Sounds pretty respectable for your program to beat you half the time. Well done.

I'm gonna start work on mine now. I dont know yet if I will try anything clever, or just a set of rules. undecided

Anyone else gonna have a go? I would like to get enough together to have a bit of a tournament!
User IP Logged

Inaliable rights:
Life, liberty and the pursuit of BASIC
kaboomer13
Senior Member
ImageImageImageImage


member is offline

Avatar

There are 10 types of people in this world: Those who know Binary and those who don't!


Homepage PM

Gender: Male
Posts: 404
xx Re: Pure coding challenge - Connect 4 AI
« Reply #12 on: May 27th, 2004, 09:47am »

I am definetly going to try out this one! I've already started, and am well on my way...

A note to all others though, remember whether your player is 1 or 2, this can be found out using the variable of player, that comes with the function.

I missed this when I started, and it took me a while to find out.

HTH


Ben Scott
User IP Logged

LBfully Yours,
Ben J Scott
Don't forget to check out DLL4LB!
Callum
Junior Member
ImageImage


member is offline

Avatar

Where there's a what there's Callum's Code.


Homepage PM

Gender: Male
Posts: 93
xx Re: Pure coding challenge - Connect 4 AI
« Reply #13 on: May 30th, 2004, 05:08am »

I've uploaded my GetNextMoveAi funtion. It keeps on beating me, but that's probably because it uses the same strategy as me.
User IP Logged

Callum
theblazingicicle
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 410
xx Re: Pure coding challenge - Connect 4 AI
« Reply #14 on: May 30th, 2004, 05:42am »

Thats a great little function, callum, very neat smiley

I am interested that you seem to give higher priority to blocking the other player than winning yourself. Is there a reason for this, because you know that once you have won, the other player has lost anyway huh

Is your program with correct variable naming on its way, Janet? Give me a shout if you want the old one deleted.
User IP Logged

Inaliable rights:
Life, liberty and the pursuit of BASIC
Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls