|
-
I just wonder if any one here has ever thought of creating Chess software, just like Deep Blue but in Flash? I want to do it, but I have no idea of what to do. Any idea guys?
-
Senior Member
If this could be done in Flash, then why did IBM create Deep Blue?
-
good idea
It could probably be done (by SOMEONE). It might take a long time 2 script the rules, it depends on what method u use. making the computer SMART would be hard though
-
Well there's two ways of making a chess game (ignoring the rules, multiplaying, colours, ect), with AI and without AI (Of course there's also with and with out AI bleh =P). Without AI Is pretty simple. You can 2D arrays or if you're anything like me who can't use 2D arrays worth ****e try:
myArray<boardx*8+boardy> = piece_string;
I'll explain that one a bit Chess boards are 8 by 8. boardx is the x position of the piece on the board. This quantity is an integer from 0 to 7, inclusive, where 7 is derived from number of squares there are from left to right. boardy is almost the same, it also is an integer between 0 and 7, inclusive, where again 7 comes from how many squares there are running up and down. but the boardy represents the y position of a piece on the board. You're probably think... Dude there's 8 squares not 7! True... but arrays don't start on 1 they start on 0, so you have to move the values down one step (from 1 to 0 and from 8 to 7). What this does is lable the board like this:
0 1 2 3 4 5 6 7
0 0 8 16 24 32 40 48 56
1 1 9 17 25 33 41 49 57
2 2 10 18 26 34 42 50 58
3 3 11 19 27 35 43 51 59
4 4 12 20 28 36 44 52 60
5 5 13 21 29 37 45 53 61
6 6 14 22 30 38 46 54 62
7 7 15 23 31 39 47 55 63
boardx*8+boardy = boardindex;
(ignore the 8 in the center by the way... that's just for the formula)
Let's try it out:
0*8+0 = 0; // YAY!
5*8+0 = 40; // JOY!
0*8+7 = 7; // YIPEE!
6*8+3 = 51; // HURRAY!
Excelent. Excelent! Muahahhahahahha MUAHAHHAHAHA.
Moving On.
So now we have our grid. Good. Now we assign pieces to our grid:
myArray<boardx*8+boardy> = piece_string;
OR
myArray<5*8+3> = "Black_Rook_Leftside";
that will put the black rook that starts on the left side at position 43 otherwise known as 5 right and 3 down;
NOTE: You could use:
myArray<boardx*7+boardy> = piece_integer; But that way you'd have to write out all of the values for the pieces... and we prolly won't be using loops either so blarg!
Now for a hitTest like equasion:
if (Black_Rook_Leftside == "wants_to_move_right") }
for (i=boardx_of_Black_Rook_Leftside+1;i<new_boardx;i+ +) {
if (myArray<i*8+boardy> != null) {
something_in_the_way = true;
}
}
}
if (!something_in_the_way) {
myArray<1*8+3> = null;
myArray<5*8+3> = "Black_Rook_Leftside";
}
That would move the Black Rook on the erm... left side.. right 4 spaces if there's nothing there, and make the old boardx and boardy postion have nothing (if you don't d othat there will be two Black Rooks that started on the lefts side... in total 3 black rooks)Hmmmmmm... Dunno... you might be clueless as to what i'm taking about, you might not. I hope this helped a bit. BYE.
NOTE: All the <'s should be ['s and the >'s should be ]'s when converted to ActionScript. And also to anyone who wants to bring 2D arrays into this discussion. PLEASE DO! I would wub to learn of em.
Somar
-
why dont yu try something simpler like othello first, the ai for this would be much easier. and the arrays given above would still be similar.
the othello ai would be based around positions on the board, and there respective value. ie a corner square is of much greater value
i hope you try it, i would love to, but as usuall there are too many things that i have going, or want to do first, anyway good luck
-
Thanks guys for all the inputs. I have done chess game (human vs human) already since Flash 4. My game has everything, from checking legal move to checking all possible moves, animated 3d pieces, etc . Now I just want to take it a step further. I want to make it so people can play against computer. The only thing I have not a vague idea about is how to make the computer think like human, to choose the best move for each move. You guys still follow me? So if you guys can point me to the direction how to do that, I would love you all.
Right now I am still thinking how to pick the best move for the computer, and still stuck at that. . Please help
-
OK this is going to be a long post.
If you are serious about this, first be aware that it will be really hard coding. Also rapidcarbon, don't start with othello (though it is a good game to use)... warm up with TIC TAC TOE.
If you understand JAVA I have coded a checkers AI as a small CS university assignment which works the way you would make a chess game. I could let you have a look at that code if you mail me.
Otherwise, this is the outline of how you would do it:
--- Create a evaluation algorithm. That is an algorithm that looks basically like
function eval(gameArray, turnColor) { code...> }
and returns an integer for how good the gameArray (specific position on the gameboard) is for turnColor (either black or white).
If position1 is a position with black slightly ahead:
function eval(position1, BLACK); returns +2
function eval(position1, WHITE); returns -2
If position2 is a position with white really ahead:
function eval(position1, BLACK); returns -243
function eval(position1, WHITE); returns +243
the eval-function calculates this based on how many pieces each player has, how good the pieces are placed and so on. Getting a good function is hard, and it can't be too big since it will be called a zillion times.
--- OK, the next step is creating a minMax algorithm.
The algorithm searches ahead a number of moves and decides which possible future position it should strive for by using the eval function. This is a recursive function looking something like this:
int NegaMax (Array gameBoard, boolean color) {
int v, Max;
Max = -MAXVALUE;
if (Ply == MaxPly) { return Eval (gameBoard, color)}
GenerateMoves (gameBoard);
for (Move = FirstMove, Move < LastMove, Move ++) {
Make (Move);
Ply++;
v = -NegaMax (gameBoard, !color);
Ply--;
Retract (Move);
if (v > Max) { Max = v;}
}
return Max;
}
This is strange JAVA/pseudocode, I know, but I hope it's understandable what it does (not how it works though).
Sorry ..... I am slowly realizing this is a bit too complex to explain in this post. If you're still interested mail me and I'll send you some stuff. I can also recommend the first chapters of (Russell & Norvig: Artificial Intelligence - A Modern Approach, Morgan Kaufman 1995) which explains these things as easy as possible :0).
You might find some information on http://www.it.lth.se/tai/lect/f03.pdf
If many people are interested I might take the time to write a tutorial on this (AI algorithms to be used in many turn-based games).
I personally don't think Flash is the place to use these kind of things but good luck anyway...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|