PDA

View Full Version : Four-in-a-row (FlashPascal program)



Roland Chastain
28-12-2012, 10:50 PM
Hello gentlemen !

I would like to present my "Four-in-a-row" game, made with Flash Pascal 2. If someone doesn't know it, FlashPascal (http://flashpascal.execute.re/) is an editor and compiler which produces Flash movies from Pascal language.

You can only play "white", while computer always plays "black".

Here is a link to my web site where you can play the game and download source files.

Four (http://www.eschecs.fr/quatre.html)

1003

I have not yet had time to make an english version, but the game is very simple and easy to use.

"A vous l'honneur !" means something like "Your move ?" :)

Dan
29-12-2012, 02:56 AM
very nice game, but the AI needs a bit more variation to make it more interesting.

WILL
29-12-2012, 03:16 AM
Nice job. Have you tried letting the computer AI play it's self? Fun experiments like that are great for exploring new game ideas and learning how to do the next cool thing in your games. :)

Great first stepping stone. What are your next project ideas?

Cybermonkey
29-12-2012, 09:49 AM
Nice to finally see a game made with FlashPascal. I hope to see more games made with it soon. If I am not mistaken, there is also an open source version of FlashPascal on SF.net.

Roland Chastain
29-12-2012, 10:28 AM
Thank you for the answers.

FlashPascal has powerful graphical functions, so it is certainly possible to make a nicer interface.
Regarding the algorithm, it's an interesting idea to introduce variations.
I have not yet tested computer versus computer game. I will try it.

@CyberMonkey

Yes, that's right. The main difference is that FlashPascal 2 has an editor, while the first version uses command-line compilation.

Here is another game made with FlashPascal :
http://flashpascal.execute.re/FlashMine.php

Cybermonkey
29-12-2012, 10:41 AM
OK I see. I hoped to see a game with (animated) sprites or so... ;)

EDIT: Erm, maybe I found a bug, just look at the attached image. Always clicking on the same row gives a "draw" although blue wins...

1005

paul_nicholls
30-12-2012, 09:44 PM
FlashPascal sounds interesting...after some fiddling around I managed to download it (http://flashpascal.execute.re/). I will have to try it after I finish my Java course :)

Thanks for sharing Roland :)

cheers,
Paul

Roland Chastain
30-12-2012, 10:47 PM
@CyberMonkey

Thank you for the bug report. It is corrected. :)


if cells[cx, 0].state <> 0 then exit;

The file to download (http://www.eschecs.fr/fichiers/p4-flashpascal.zip) has been replaced.


@paul_nicholls

Thank you for your attention. :)

Roland Chastain
22-08-2013, 08:11 PM
Hello gentlemen !

I have rewritten my Four-in-a-row (http://www.eschecs.fr/quatre.html). The internal functions are new. The interface is almost the same, except that there are checkboxes to select the game mode.

If ever you wish to compile the source code, you have to dowload separately the small library (http://flashpascal.execute.re/FlashCL.php) I used for checkboxes.

Best regards.

Roland

Dan
23-08-2013, 02:39 PM
any way to increase the difficulty?=)

WILL
23-08-2013, 04:54 PM
Hey nice work! I like the nice sleek clean look to your screenshots.

Any interest in the current PGD Challenge (http://www.pascalgamedevelopment.com/content.php?377-3rd-PGD-Challenge-At-Your-Command!)?

A lot of game developers from all skill levels really enjoy taking part and it doesn't even have to be overly complex either. Though many do try. :)

Keep making games.

SilverWarior
23-08-2013, 06:53 PM
any way to increase the difficulty?=)

On Delphi About there is an interesting article about adding Artifical Intelligence to games. Article shows how to make "self learning AI" in Nepali game named "GATTA TIPNE KHEL" (meaning pebble picking game).
http://delphi.about.com/od/gameprogramming/a/aigamesample.htm
It would be posiible to implement similar approach into "Four in a row" game which would make game harder and harder the more you play, making it almost unbetable at the end.

Roland Chastain
18-04-2014, 12:41 PM
Hello! I would like to present the new version of my FlashPascal Four-in-row. The interface has been remade. The engine is the one (with small adaptations) I used in my Lazarus project.

You can play the game on line (http://www.eschecs.fr/quatre.html). It should detect the local language (limited to english, german and french) and display the appropriate messages.

SilverWarior
18-04-2014, 06:05 PM
Is it just my opinion or you also did some work on AI making it smarter?

Roland Chastain
18-04-2014, 07:30 PM
Is it just my opinion or you also did some work on AI making it smarter?

Indeed, I remade the AI. I hope I made it better. :)

The evaluation procedure is more precise. I use an array of all good sequences. Each sequence found increase the result.


const motifs: array[0..13, 0..1]of string = (
('OOOO', 'XXXX'),
('OOO.', 'XXX.'),
('.OOO', '.XXX'),
('OO.O', 'XX.X'),
('O.OO', 'X.XX'),
('OO..', 'XX..'),
('O.O.', 'X.X.'),
('O..O', 'X..X'),
('.O.O', '.X.X'),
('..OO', '..XX'),
('O...', 'X...'),
('.O..', '.X..'),
('..O.', '..X.'),
('...O', '...X')
);


const
demiDroites: array[0..24, 0..3] of integer = (
(1, 1, +1, 0),
(1, 2, +1, 0),
(1, 3, +1, 0),
(1, 4, +1, 0),
(1, 5, +1, 0),
(1, 6, +1, 0),
(1, 1, 0, +1),
(2, 1, 0, +1),
(3, 1, 0, +1),
(4, 1, 0, +1),
(5, 1, 0, +1),
(6, 1, 0, +1),
(7, 1, 0, +1),
(1, 1, +1, +1),
(1, 2, +1, +1),
(1, 3, +1, +1),
(1, 4, +1, -1),
(1, 5, +1, -1),
(1, 6, +1, -1),
(7, 1, -1, +1),
(7, 2, -1, +1),
(7, 3, -1, +1),
(7, 4, -1, -1),
(7, 5, -1, -1),
(7, 6, -1, -1)
);


function tClasseGrille.Points(const aPion: char): integer;
var
i, j, k, l: integer;
x, y: integer;
segment: string;
begin
result := 0;
l := Ord(aPion = BLANC);

for i := Low(demiDroites) to High(demiDroites) do
begin
x := demiDroites[i, 0];
y := demiDroites[i, 1];

segment := ' ';

j := 1;
repeat
segment[j] := grille[x, y];
Inc(x, demiDroites[i, 2]);
Inc(y, demiDroites[i, 3]);
Inc(j);
until (x < UN) or (x > SEPT) or (y < UN) or (y > SIX);

for j := Low(motifs) to High(motifs) do
if Pos(motifs[j, l], segment) > 0 then
begin
case j of
0:
k := 75000;
1..4:
k := 2500;
5..9:
k := 50;
else
k := 1;
end;
Inc(result, k);
end;
end;
end;

SilverWarior
19-04-2014, 09:59 AM
Indeed, I remade the AI. I hope I made it better. :)

It made it much harder. So far after about a dozen plays I haven't won even once. Lost two times and the rest times resulted in draw.
But now the AI moves seems ... artificial. When you are playing AI doesen't just prevent you from winning but on my opinion prevent you even from coming close to winning.
In all my lays I havent managed to reach a point where I would have tre in a row and AI would be forced to block the fourth one. AI simply folows certain path were it even prevents you to prepare any posible winning situation. And this is a joy killer.

Roland Chastain
19-04-2014, 10:12 AM
AI simply follows certain path were it even prevents you to prepare any posible winning situation.

Yes, it's a very good observation.


if Max(a) >= 2500 then
result := IndexOf(a, Min(a))

The a variable is an array of the maximal opponent's score at next move. And 2500 means three stones aligned.


And this is a joy killer.

Yes, I see what you mean. I will keep it in mind. Anyway thank you for trying my program and for your instructive report.

SilverWarior
19-04-2014, 09:35 PM
All you have to do is add some randomization into your AI calculations which would alow it to make some unsafe move every now and then. This would make AI moves to feel omre human.

If you need someone to playtest and analyze your game I'm usually up for it. You would be surprised how much I have learned this way.

Dan
20-04-2014, 04:21 AM
hasn't been able to beat me even once, so still needs more improvement;)

Roland Chastain
20-04-2014, 07:20 AM
All you have to do is add some randomization into your AI calculations which would alow it to make some unsafe move every now and then. This would make AI moves to feel more human.

If you need someone to playtest and analyze your game I'm usually up for it. You would be surprised how much I have learned this way.

Thank you for your suggestion and for your willingness to help.


hasn't been able to beat me even once, so still needs more improvement;)

Thank you for testing. I hope I will improve it soon. :)

Happy Easter!

Roland Chastain
20-04-2014, 09:47 AM
I made a quick modification inspired by SilverWarior's suggestion.

I hope the code is clearer than my explanation would be. :)


aux := Max(a);

//if Max(a) >= BONUS[3] then

if (aux >= BONUS[4]) or (aux >= BONUS[3]) and (RandomAB(1, 2) < 2) then
result := IndexOf(a, Min(a))

And here is an example of a bad move than the previous formula used to avoid : DDCC (computer plays black).

Dan
20-04-2014, 11:39 AM
the difference is noticeable there is some randomness in the AI's decisions, but very often that leads to bad moves. still can't beat me=)