SlideShare a Scribd company logo
1 of 12
Download to read offline
#include
#include
#include
#include
#include "game.h"
#include "aaball.h"
#define CHECKERS_CELL_SIZE 40
#define CHECKERS_NUM_PIECES 4
#define CHECKERS_BOARD_WID 8
#define CHECKERS_BOARD_HEIT 8
#define CHECKERS_WK 1
#define CHECKERS_WP 2
#define CHECKERS_BK 3
#define CHECKERS_BP 4
#define CHECKERS_ISKING(x) (x == 1 || x == 3)
#define CHECKERS_ISPAWN(x) (x == 2 || x == 4)
#define CHECKERS_ISWHITE(x) (x >= 1 && x <= 2)
#define CHECKERS_ISBLACK(x) (x >= 3 && x <= 4)
char checkers_colors[] =
{200, 200, 200,
220,220,255};
int checkers_init_pos[] =
{
0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 ,
4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 ,
0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 ,
0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 ,
2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 ,
};
static int checkers_max_moves = 200;
void checkers_init ();
int checkers_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
ResultType checkers_who_won (Pos *, Player, char **);
byte *checkers_movegen (Pos *);
ResultType checkers_eval (Pos *, Player, float *);
char ** checkers_get_pixmap (int idx, int color);
void checkers_reset_uistate ();
Game Checkers =
{ CHECKERS_CELL_SIZE, CHECKERS_BOARD_WID,
CHECKERS_BOARD_HEIT,
CHECKERS_NUM_PIECES,
checkers_colors, checkers_init_pos, NULL, "Checkers",
checkers_init};
void checkers_init ()
{
game_getmove = checkers_getmove;
game_movegen = checkers_movegen;
game_who_won = checkers_who_won;
game_eval = checkers_eval;
game_get_pixmap = checkers_get_pixmap;
game_reset_uistate = checkers_reset_uistate;
game_file_label = FILERANK_LABEL_TYPE_ALPHA;
game_rank_label = FILERANK_LABEL_TYPE_NUM | FILERANK_LABEL_DESC;
game_allow_flip = TRUE;
game_doc_about =
"Checkers "
"Two player game "
"Status: Partially implemented (currently unplayable) "
"URL: "GAME_DEFAULT_URL("checkers");
}
ResultType checkers_who_won (Pos *pos, Player player, char **commp)
{
static char comment[32];
char *who_str [2] = { "white won", "black won"};
int found_w = 0, found_b = 0;
int i;
for (i=0; iboard[i])) found_w = 1;
else if (CHECKERS_ISBLACK (pos->board[i])) found_b = 1;
if (!found_b)
{
strncpy (comment, who_str[0], 31);
*commp = comment;
return RESULT_WHITE;
}
if (!found_w)
{
strncpy (comment, who_str[1], 31);
*commp = comment;
return RESULT_BLACK;
}
return RESULT_NOTYET;
}
byte * checkers_movegen (Pos *pos)
{
int i, j, diffx, diffy;
byte movbuf [256];
byte *movlist, *mp = movbuf;
byte *board = pos->board;
Player player = pos->player;
for (i=0; iboard [j * board_wid + i])
{
case CHECKERS_WK: sum += (5 - fabs ((i-3.5) * (j-3.5)) / 10); break;
case CHECKERS_WP: sum += (1 + j / 10.0); break;
case CHECKERS_BK: sum -= (5 - fabs ((i-3.5) * (j-3.5)) / 10); break;
case CHECKERS_BP: sum -= (1 + (board_heit - 1 - j) / 10.0); break;
}
}
*eval = sum;
return RESULT_NOTYET;
}
static int oldx = -1, oldy = -1;
void checkers_reset_uistate ()
{
oldx = -1, oldy = -1;
}
int checkers_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play,
byte **movp, int ** rmovep)
{
static byte move[10];
byte *mp = move;
int diffx, diffy;
byte *board = pos->board;
if (type != GTKBOARD_BUTTON_RELEASE) return 0;
if (oldx < 0)
{
int val = board [y * board_wid + x];
if ((CHECKERS_ISWHITE(val) && !(to_play == WHITE)) ||
(CHECKERS_ISBLACK(val) && !(to_play == BLACK)))
return -1;
oldx = x; oldy = y;
return 0;
}
if (x == oldx && y == oldy)
{
oldx = -1; oldy = -1; return 0;
}
diffx = x - oldx;
if (abs (diffx) == 1)
{
diffy = y - oldy;
if (abs (diffy) != 1)
{ oldx = oldy = -1; return -1;}
if (!CHECKERS_ISKING(board [oldy * board_wid + oldx])
&& diffy != (to_play == WHITE ? 1 : -1))
{ oldx = oldy = -1; return -1;}
if (board [y * board_wid + x] != 0)
{ oldx = oldy = -1; return -1;}
*mp++ = oldx; *mp++ = oldy; *mp++ = 0;
*mp++ = x; *mp++ = y;
if ((to_play == WHITE && y == board_heit - 1)
|| (to_play == BLACK && y == 0))
*mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK);
else
*mp++ = board [oldy * board_wid + oldx];
*mp++ = -1;
*movp = move;
oldx = oldy = -1;
return 1;
}
if (abs (diffx) == 2)
{
int val;
diffy = y - oldy;
if (abs (diffy) != 2)
{ oldx = oldy = -1; return -1;}
if (!CHECKERS_ISKING(board [oldy * board_wid + oldx])
&& diffy != (to_play == WHITE ? 2 : -2))
{ oldx = oldy = -1; return -1;}
if (board [y * board_wid + x] != 0)
{ oldx = oldy = -1; return -1;}
val = board [(y-diffy/2) * board_wid + (x-diffx/2)];
if ((!CHECKERS_ISWHITE(val) && (to_play == BLACK)) ||
(!CHECKERS_ISBLACK(val) && (to_play == WHITE)))
{ oldx = oldy = -1; return -1;}
*mp++ = oldx; *mp++ = oldy; *mp++ = 0;
*mp++ = oldx+diffx/2; *mp++ = oldy+diffy/2; *mp++ = 0;
*mp++ = x; *mp++ = y;
if ((to_play == WHITE && y == board_heit - 1)
|| (to_play == BLACK && y == 0))
*mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK);
else
*mp++ = board [oldy * board_wid + oldx];
*mp++ = -1;
*movp = move;
oldx = oldy = -1;
return 1;
}
{ oldx = oldy = -1; return -1;}
}
char ** checkers_get_pixmap (int idx, int color)
{
int bg;
int i;
static char pixbuf[CHECKERS_CELL_SIZE * (CHECKERS_CELL_SIZE+1)];
for(i=0, bg=0;i<3;i++)
{ int col = checkers_colors[i+3];
if (col<0) col += 256; bg += col * (1 << (16-8*i));}
return pixmap_ball_gen (CHECKERS_CELL_SIZE, pixbuf,
CHECKERS_ISWHITE(idx) ? 0xffffff : 0x0000ff, bg,
(idx == CHECKERS_WP || idx == CHECKERS_BP) ? 8 : 12, 24);
}
Solution
#include
#include
#include
#include
#include "game.h"
#include "aaball.h"
#define CHECKERS_CELL_SIZE 40
#define CHECKERS_NUM_PIECES 4
#define CHECKERS_BOARD_WID 8
#define CHECKERS_BOARD_HEIT 8
#define CHECKERS_WK 1
#define CHECKERS_WP 2
#define CHECKERS_BK 3
#define CHECKERS_BP 4
#define CHECKERS_ISKING(x) (x == 1 || x == 3)
#define CHECKERS_ISPAWN(x) (x == 2 || x == 4)
#define CHECKERS_ISWHITE(x) (x >= 1 && x <= 2)
#define CHECKERS_ISBLACK(x) (x >= 3 && x <= 4)
char checkers_colors[] =
{200, 200, 200,
220,220,255};
int checkers_init_pos[] =
{
0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 ,
4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 ,
0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 ,
0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 ,
2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 ,
};
static int checkers_max_moves = 200;
void checkers_init ();
int checkers_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
ResultType checkers_who_won (Pos *, Player, char **);
byte *checkers_movegen (Pos *);
ResultType checkers_eval (Pos *, Player, float *);
char ** checkers_get_pixmap (int idx, int color);
void checkers_reset_uistate ();
Game Checkers =
{ CHECKERS_CELL_SIZE, CHECKERS_BOARD_WID,
CHECKERS_BOARD_HEIT,
CHECKERS_NUM_PIECES,
checkers_colors, checkers_init_pos, NULL, "Checkers",
checkers_init};
void checkers_init ()
{
game_getmove = checkers_getmove;
game_movegen = checkers_movegen;
game_who_won = checkers_who_won;
game_eval = checkers_eval;
game_get_pixmap = checkers_get_pixmap;
game_reset_uistate = checkers_reset_uistate;
game_file_label = FILERANK_LABEL_TYPE_ALPHA;
game_rank_label = FILERANK_LABEL_TYPE_NUM | FILERANK_LABEL_DESC;
game_allow_flip = TRUE;
game_doc_about =
"Checkers "
"Two player game "
"Status: Partially implemented (currently unplayable) "
"URL: "GAME_DEFAULT_URL("checkers");
}
ResultType checkers_who_won (Pos *pos, Player player, char **commp)
{
static char comment[32];
char *who_str [2] = { "white won", "black won"};
int found_w = 0, found_b = 0;
int i;
for (i=0; iboard[i])) found_w = 1;
else if (CHECKERS_ISBLACK (pos->board[i])) found_b = 1;
if (!found_b)
{
strncpy (comment, who_str[0], 31);
*commp = comment;
return RESULT_WHITE;
}
if (!found_w)
{
strncpy (comment, who_str[1], 31);
*commp = comment;
return RESULT_BLACK;
}
return RESULT_NOTYET;
}
byte * checkers_movegen (Pos *pos)
{
int i, j, diffx, diffy;
byte movbuf [256];
byte *movlist, *mp = movbuf;
byte *board = pos->board;
Player player = pos->player;
for (i=0; iboard [j * board_wid + i])
{
case CHECKERS_WK: sum += (5 - fabs ((i-3.5) * (j-3.5)) / 10); break;
case CHECKERS_WP: sum += (1 + j / 10.0); break;
case CHECKERS_BK: sum -= (5 - fabs ((i-3.5) * (j-3.5)) / 10); break;
case CHECKERS_BP: sum -= (1 + (board_heit - 1 - j) / 10.0); break;
}
}
*eval = sum;
return RESULT_NOTYET;
}
static int oldx = -1, oldy = -1;
void checkers_reset_uistate ()
{
oldx = -1, oldy = -1;
}
int checkers_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play,
byte **movp, int ** rmovep)
{
static byte move[10];
byte *mp = move;
int diffx, diffy;
byte *board = pos->board;
if (type != GTKBOARD_BUTTON_RELEASE) return 0;
if (oldx < 0)
{
int val = board [y * board_wid + x];
if ((CHECKERS_ISWHITE(val) && !(to_play == WHITE)) ||
(CHECKERS_ISBLACK(val) && !(to_play == BLACK)))
return -1;
oldx = x; oldy = y;
return 0;
}
if (x == oldx && y == oldy)
{
oldx = -1; oldy = -1; return 0;
}
diffx = x - oldx;
if (abs (diffx) == 1)
{
diffy = y - oldy;
if (abs (diffy) != 1)
{ oldx = oldy = -1; return -1;}
if (!CHECKERS_ISKING(board [oldy * board_wid + oldx])
&& diffy != (to_play == WHITE ? 1 : -1))
{ oldx = oldy = -1; return -1;}
if (board [y * board_wid + x] != 0)
{ oldx = oldy = -1; return -1;}
*mp++ = oldx; *mp++ = oldy; *mp++ = 0;
*mp++ = x; *mp++ = y;
if ((to_play == WHITE && y == board_heit - 1)
|| (to_play == BLACK && y == 0))
*mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK);
else
*mp++ = board [oldy * board_wid + oldx];
*mp++ = -1;
*movp = move;
oldx = oldy = -1;
return 1;
}
if (abs (diffx) == 2)
{
int val;
diffy = y - oldy;
if (abs (diffy) != 2)
{ oldx = oldy = -1; return -1;}
if (!CHECKERS_ISKING(board [oldy * board_wid + oldx])
&& diffy != (to_play == WHITE ? 2 : -2))
{ oldx = oldy = -1; return -1;}
if (board [y * board_wid + x] != 0)
{ oldx = oldy = -1; return -1;}
val = board [(y-diffy/2) * board_wid + (x-diffx/2)];
if ((!CHECKERS_ISWHITE(val) && (to_play == BLACK)) ||
(!CHECKERS_ISBLACK(val) && (to_play == WHITE)))
{ oldx = oldy = -1; return -1;}
*mp++ = oldx; *mp++ = oldy; *mp++ = 0;
*mp++ = oldx+diffx/2; *mp++ = oldy+diffy/2; *mp++ = 0;
*mp++ = x; *mp++ = y;
if ((to_play == WHITE && y == board_heit - 1)
|| (to_play == BLACK && y == 0))
*mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK);
else
*mp++ = board [oldy * board_wid + oldx];
*mp++ = -1;
*movp = move;
oldx = oldy = -1;
return 1;
}
{ oldx = oldy = -1; return -1;}
}
char ** checkers_get_pixmap (int idx, int color)
{
int bg;
int i;
static char pixbuf[CHECKERS_CELL_SIZE * (CHECKERS_CELL_SIZE+1)];
for(i=0, bg=0;i<3;i++)
{ int col = checkers_colors[i+3];
if (col<0) col += 256; bg += col * (1 << (16-8*i));}
return pixmap_ball_gen (CHECKERS_CELL_SIZE, pixbuf,
CHECKERS_ISWHITE(idx) ? 0xffffff : 0x0000ff, bg,
(idx == CHECKERS_WP || idx == CHECKERS_BP) ? 8 : 12, 24);
}

More Related Content

Similar to #include stdio.h #include string.h #include stdlib.h #in.pdf

package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfinfo430661
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)SETYA HADI
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)SETYA HADI
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfanjandavid
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212Mahmoud Samir Fayed
 
Sql
SqlSql
SqlJoao
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdfNayanOza
 
#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdfsudhinjv
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
include ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfinclude ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfadisainternational
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscationguest9006ab
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilNova Patch
 

Similar to #include stdio.h #include string.h #include stdlib.h #in.pdf (14)

package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)
 
Bubble archery game(c program)
Bubble archery game(c program)Bubble archery game(c program)
Bubble archery game(c program)
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
Sql
SqlSql
Sql
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
Python From Scratch (1).pdf
Python From Scratch  (1).pdfPython From Scratch  (1).pdf
Python From Scratch (1).pdf
 
#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf#include iostream #include string #include iomanip #incl.pdf
#include iostream #include string #include iomanip #incl.pdf
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
include ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfinclude ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdf
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 

More from singhanubhav1234

the Zn(OH)2 precipitation reaction equation Zn2.pdf
                     the Zn(OH)2 precipitation reaction equation  Zn2.pdf                     the Zn(OH)2 precipitation reaction equation  Zn2.pdf
the Zn(OH)2 precipitation reaction equation Zn2.pdfsinghanubhav1234
 
The side facing the SUN will absorb Infra-red rad.pdf
                     The side facing the SUN will absorb Infra-red rad.pdf                     The side facing the SUN will absorb Infra-red rad.pdf
The side facing the SUN will absorb Infra-red rad.pdfsinghanubhav1234
 
Stereoisomers are isomeric molecules that have th.pdf
                     Stereoisomers are isomeric molecules that have th.pdf                     Stereoisomers are isomeric molecules that have th.pdf
Stereoisomers are isomeric molecules that have th.pdfsinghanubhav1234
 
Salt dissolving in water physical or chemical Def.pdf
                     Salt dissolving in water physical or chemical Def.pdf                     Salt dissolving in water physical or chemical Def.pdf
Salt dissolving in water physical or chemical Def.pdfsinghanubhav1234
 
POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf
                     POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf                     POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf
POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdfsinghanubhav1234
 
Not really. Strontium carbonate can only dissolve.pdf
                     Not really. Strontium carbonate can only dissolve.pdf                     Not really. Strontium carbonate can only dissolve.pdf
Not really. Strontium carbonate can only dissolve.pdfsinghanubhav1234
 
Lattice energy increases with charge multiplicity.pdf
                     Lattice energy increases with charge multiplicity.pdf                     Lattice energy increases with charge multiplicity.pdf
Lattice energy increases with charge multiplicity.pdfsinghanubhav1234
 
Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf
                     Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf                     Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf
Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdfsinghanubhav1234
 
The answer isD. they are significantly higher than the boiling po.pdf
The answer isD. they are significantly higher than the boiling po.pdfThe answer isD. they are significantly higher than the boiling po.pdf
The answer isD. they are significantly higher than the boiling po.pdfsinghanubhav1234
 
Silica Fume is a very reactive pozzolana because of its chemical and.pdf
Silica Fume is a very reactive pozzolana because of its chemical and.pdfSilica Fume is a very reactive pozzolana because of its chemical and.pdf
Silica Fume is a very reactive pozzolana because of its chemical and.pdfsinghanubhav1234
 
Problem 01 #!usrbinperl use strict; use warnings; $_ = .pdf
Problem 01 #!usrbinperl use strict; use warnings; $_ = .pdfProblem 01 #!usrbinperl use strict; use warnings; $_ = .pdf
Problem 01 #!usrbinperl use strict; use warnings; $_ = .pdfsinghanubhav1234
 
enzymes active site does not have the exact sha.pdf
                     enzymes active site does not have the exact sha.pdf                     enzymes active site does not have the exact sha.pdf
enzymes active site does not have the exact sha.pdfsinghanubhav1234
 
MulticastingIt is the communication between a single sender and m.pdf
MulticastingIt is the communication between a single sender and m.pdfMulticastingIt is the communication between a single sender and m.pdf
MulticastingIt is the communication between a single sender and m.pdfsinghanubhav1234
 
just moved a new USB 2.0 device from a new system to an older system.pdf
just moved a new USB 2.0 device from a new system to an older system.pdfjust moved a new USB 2.0 device from a new system to an older system.pdf
just moved a new USB 2.0 device from a new system to an older system.pdfsinghanubhav1234
 
IntroductionFew things are more aggravating to produce on a worksi.pdf
IntroductionFew things are more aggravating to produce on a worksi.pdfIntroductionFew things are more aggravating to produce on a worksi.pdf
IntroductionFew things are more aggravating to produce on a worksi.pdfsinghanubhav1234
 
D) Rb Solution D) Rb .pdf
                     D) Rb  Solution                     D) Rb  .pdf                     D) Rb  Solution                     D) Rb  .pdf
D) Rb Solution D) Rb .pdfsinghanubhav1234
 
function [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdf
function [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdffunction [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdf
function [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdfsinghanubhav1234
 
Evolution of mitochondria.Mitochondria are believed to have arisen.pdf
Evolution of mitochondria.Mitochondria are believed to have arisen.pdfEvolution of mitochondria.Mitochondria are believed to have arisen.pdf
Evolution of mitochondria.Mitochondria are believed to have arisen.pdfsinghanubhav1234
 

More from singhanubhav1234 (20)

the Zn(OH)2 precipitation reaction equation Zn2.pdf
                     the Zn(OH)2 precipitation reaction equation  Zn2.pdf                     the Zn(OH)2 precipitation reaction equation  Zn2.pdf
the Zn(OH)2 precipitation reaction equation Zn2.pdf
 
The side facing the SUN will absorb Infra-red rad.pdf
                     The side facing the SUN will absorb Infra-red rad.pdf                     The side facing the SUN will absorb Infra-red rad.pdf
The side facing the SUN will absorb Infra-red rad.pdf
 
Stereoisomers are isomeric molecules that have th.pdf
                     Stereoisomers are isomeric molecules that have th.pdf                     Stereoisomers are isomeric molecules that have th.pdf
Stereoisomers are isomeric molecules that have th.pdf
 
Salt dissolving in water physical or chemical Def.pdf
                     Salt dissolving in water physical or chemical Def.pdf                     Salt dissolving in water physical or chemical Def.pdf
Salt dissolving in water physical or chemical Def.pdf
 
POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf
                     POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf                     POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf
POH=-log[OH-] =-log(0.005) =2.301 PH=14-2.301=11..pdf
 
Not really. Strontium carbonate can only dissolve.pdf
                     Not really. Strontium carbonate can only dissolve.pdf                     Not really. Strontium carbonate can only dissolve.pdf
Not really. Strontium carbonate can only dissolve.pdf
 
Lattice energy increases with charge multiplicity.pdf
                     Lattice energy increases with charge multiplicity.pdf                     Lattice energy increases with charge multiplicity.pdf
Lattice energy increases with charge multiplicity.pdf
 
Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf
                     Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf                     Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf
Lucas Test uses HCl and ZnCl2, it proceeds via Sn.pdf
 
The answer isD. they are significantly higher than the boiling po.pdf
The answer isD. they are significantly higher than the boiling po.pdfThe answer isD. they are significantly higher than the boiling po.pdf
The answer isD. they are significantly higher than the boiling po.pdf
 
Silica Fume is a very reactive pozzolana because of its chemical and.pdf
Silica Fume is a very reactive pozzolana because of its chemical and.pdfSilica Fume is a very reactive pozzolana because of its chemical and.pdf
Silica Fume is a very reactive pozzolana because of its chemical and.pdf
 
Problem 01 #!usrbinperl use strict; use warnings; $_ = .pdf
Problem 01 #!usrbinperl use strict; use warnings; $_ = .pdfProblem 01 #!usrbinperl use strict; use warnings; $_ = .pdf
Problem 01 #!usrbinperl use strict; use warnings; $_ = .pdf
 
enzymes active site does not have the exact sha.pdf
                     enzymes active site does not have the exact sha.pdf                     enzymes active site does not have the exact sha.pdf
enzymes active site does not have the exact sha.pdf
 
MulticastingIt is the communication between a single sender and m.pdf
MulticastingIt is the communication between a single sender and m.pdfMulticastingIt is the communication between a single sender and m.pdf
MulticastingIt is the communication between a single sender and m.pdf
 
just moved a new USB 2.0 device from a new system to an older system.pdf
just moved a new USB 2.0 device from a new system to an older system.pdfjust moved a new USB 2.0 device from a new system to an older system.pdf
just moved a new USB 2.0 device from a new system to an older system.pdf
 
IntroductionFew things are more aggravating to produce on a worksi.pdf
IntroductionFew things are more aggravating to produce on a worksi.pdfIntroductionFew things are more aggravating to produce on a worksi.pdf
IntroductionFew things are more aggravating to produce on a worksi.pdf
 
D) Rb Solution D) Rb .pdf
                     D) Rb  Solution                     D) Rb  .pdf                     D) Rb  Solution                     D) Rb  .pdf
D) Rb Solution D) Rb .pdf
 
idkSolutionidk.pdf
idkSolutionidk.pdfidkSolutionidk.pdf
idkSolutionidk.pdf
 
function [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdf
function [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdffunction [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdf
function [M]=trajectory3(x,y,z,pitcher,roll,yaw,scale_factor,step,se.pdf
 
Evolution of mitochondria.Mitochondria are believed to have arisen.pdf
Evolution of mitochondria.Mitochondria are believed to have arisen.pdfEvolution of mitochondria.Mitochondria are believed to have arisen.pdf
Evolution of mitochondria.Mitochondria are believed to have arisen.pdf
 
DSolutionD.pdf
DSolutionD.pdfDSolutionD.pdf
DSolutionD.pdf
 

Recently uploaded

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

#include stdio.h #include string.h #include stdlib.h #in.pdf

  • 1. #include #include #include #include #include "game.h" #include "aaball.h" #define CHECKERS_CELL_SIZE 40 #define CHECKERS_NUM_PIECES 4 #define CHECKERS_BOARD_WID 8 #define CHECKERS_BOARD_HEIT 8 #define CHECKERS_WK 1 #define CHECKERS_WP 2 #define CHECKERS_BK 3 #define CHECKERS_BP 4 #define CHECKERS_ISKING(x) (x == 1 || x == 3) #define CHECKERS_ISPAWN(x) (x == 2 || x == 4) #define CHECKERS_ISWHITE(x) (x >= 1 && x <= 2) #define CHECKERS_ISBLACK(x) (x >= 3 && x <= 4) char checkers_colors[] = {200, 200, 200, 220,220,255}; int checkers_init_pos[] = { 0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 , 4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 , 0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 , 2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , }; static int checkers_max_moves = 200;
  • 2. void checkers_init (); int checkers_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **); ResultType checkers_who_won (Pos *, Player, char **); byte *checkers_movegen (Pos *); ResultType checkers_eval (Pos *, Player, float *); char ** checkers_get_pixmap (int idx, int color); void checkers_reset_uistate (); Game Checkers = { CHECKERS_CELL_SIZE, CHECKERS_BOARD_WID, CHECKERS_BOARD_HEIT, CHECKERS_NUM_PIECES, checkers_colors, checkers_init_pos, NULL, "Checkers", checkers_init}; void checkers_init () { game_getmove = checkers_getmove; game_movegen = checkers_movegen; game_who_won = checkers_who_won; game_eval = checkers_eval; game_get_pixmap = checkers_get_pixmap; game_reset_uistate = checkers_reset_uistate; game_file_label = FILERANK_LABEL_TYPE_ALPHA; game_rank_label = FILERANK_LABEL_TYPE_NUM | FILERANK_LABEL_DESC; game_allow_flip = TRUE; game_doc_about = "Checkers " "Two player game " "Status: Partially implemented (currently unplayable) " "URL: "GAME_DEFAULT_URL("checkers"); } ResultType checkers_who_won (Pos *pos, Player player, char **commp) { static char comment[32]; char *who_str [2] = { "white won", "black won"}; int found_w = 0, found_b = 0;
  • 3. int i; for (i=0; iboard[i])) found_w = 1; else if (CHECKERS_ISBLACK (pos->board[i])) found_b = 1; if (!found_b) { strncpy (comment, who_str[0], 31); *commp = comment; return RESULT_WHITE; } if (!found_w) { strncpy (comment, who_str[1], 31); *commp = comment; return RESULT_BLACK; } return RESULT_NOTYET; } byte * checkers_movegen (Pos *pos) { int i, j, diffx, diffy; byte movbuf [256]; byte *movlist, *mp = movbuf; byte *board = pos->board; Player player = pos->player; for (i=0; iboard [j * board_wid + i]) { case CHECKERS_WK: sum += (5 - fabs ((i-3.5) * (j-3.5)) / 10); break; case CHECKERS_WP: sum += (1 + j / 10.0); break; case CHECKERS_BK: sum -= (5 - fabs ((i-3.5) * (j-3.5)) / 10); break; case CHECKERS_BP: sum -= (1 + (board_heit - 1 - j) / 10.0); break; } } *eval = sum; return RESULT_NOTYET; }
  • 4. static int oldx = -1, oldy = -1; void checkers_reset_uistate () { oldx = -1, oldy = -1; } int checkers_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play, byte **movp, int ** rmovep) { static byte move[10]; byte *mp = move; int diffx, diffy; byte *board = pos->board; if (type != GTKBOARD_BUTTON_RELEASE) return 0; if (oldx < 0) { int val = board [y * board_wid + x]; if ((CHECKERS_ISWHITE(val) && !(to_play == WHITE)) || (CHECKERS_ISBLACK(val) && !(to_play == BLACK))) return -1; oldx = x; oldy = y; return 0; } if (x == oldx && y == oldy) { oldx = -1; oldy = -1; return 0; } diffx = x - oldx; if (abs (diffx) == 1) { diffy = y - oldy; if (abs (diffy) != 1)
  • 5. { oldx = oldy = -1; return -1;} if (!CHECKERS_ISKING(board [oldy * board_wid + oldx]) && diffy != (to_play == WHITE ? 1 : -1)) { oldx = oldy = -1; return -1;} if (board [y * board_wid + x] != 0) { oldx = oldy = -1; return -1;} *mp++ = oldx; *mp++ = oldy; *mp++ = 0; *mp++ = x; *mp++ = y; if ((to_play == WHITE && y == board_heit - 1) || (to_play == BLACK && y == 0)) *mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK); else *mp++ = board [oldy * board_wid + oldx]; *mp++ = -1; *movp = move; oldx = oldy = -1; return 1; } if (abs (diffx) == 2) { int val; diffy = y - oldy; if (abs (diffy) != 2) { oldx = oldy = -1; return -1;} if (!CHECKERS_ISKING(board [oldy * board_wid + oldx]) && diffy != (to_play == WHITE ? 2 : -2)) { oldx = oldy = -1; return -1;} if (board [y * board_wid + x] != 0) { oldx = oldy = -1; return -1;} val = board [(y-diffy/2) * board_wid + (x-diffx/2)]; if ((!CHECKERS_ISWHITE(val) && (to_play == BLACK)) || (!CHECKERS_ISBLACK(val) && (to_play == WHITE))) { oldx = oldy = -1; return -1;} *mp++ = oldx; *mp++ = oldy; *mp++ = 0; *mp++ = oldx+diffx/2; *mp++ = oldy+diffy/2; *mp++ = 0; *mp++ = x; *mp++ = y;
  • 6. if ((to_play == WHITE && y == board_heit - 1) || (to_play == BLACK && y == 0)) *mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK); else *mp++ = board [oldy * board_wid + oldx]; *mp++ = -1; *movp = move; oldx = oldy = -1; return 1; } { oldx = oldy = -1; return -1;} } char ** checkers_get_pixmap (int idx, int color) { int bg; int i; static char pixbuf[CHECKERS_CELL_SIZE * (CHECKERS_CELL_SIZE+1)]; for(i=0, bg=0;i<3;i++) { int col = checkers_colors[i+3]; if (col<0) col += 256; bg += col * (1 << (16-8*i));} return pixmap_ball_gen (CHECKERS_CELL_SIZE, pixbuf, CHECKERS_ISWHITE(idx) ? 0xffffff : 0x0000ff, bg, (idx == CHECKERS_WP || idx == CHECKERS_BP) ? 8 : 12, 24); } Solution #include #include #include #include #include "game.h" #include "aaball.h" #define CHECKERS_CELL_SIZE 40 #define CHECKERS_NUM_PIECES 4
  • 7. #define CHECKERS_BOARD_WID 8 #define CHECKERS_BOARD_HEIT 8 #define CHECKERS_WK 1 #define CHECKERS_WP 2 #define CHECKERS_BK 3 #define CHECKERS_BP 4 #define CHECKERS_ISKING(x) (x == 1 || x == 3) #define CHECKERS_ISPAWN(x) (x == 2 || x == 4) #define CHECKERS_ISWHITE(x) (x >= 1 && x <= 2) #define CHECKERS_ISBLACK(x) (x >= 3 && x <= 4) char checkers_colors[] = {200, 200, 200, 220,220,255}; int checkers_init_pos[] = { 0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 , 4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 , 0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 , 2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 , }; static int checkers_max_moves = 200; void checkers_init (); int checkers_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **); ResultType checkers_who_won (Pos *, Player, char **); byte *checkers_movegen (Pos *); ResultType checkers_eval (Pos *, Player, float *); char ** checkers_get_pixmap (int idx, int color); void checkers_reset_uistate (); Game Checkers = { CHECKERS_CELL_SIZE, CHECKERS_BOARD_WID,
  • 8. CHECKERS_BOARD_HEIT, CHECKERS_NUM_PIECES, checkers_colors, checkers_init_pos, NULL, "Checkers", checkers_init}; void checkers_init () { game_getmove = checkers_getmove; game_movegen = checkers_movegen; game_who_won = checkers_who_won; game_eval = checkers_eval; game_get_pixmap = checkers_get_pixmap; game_reset_uistate = checkers_reset_uistate; game_file_label = FILERANK_LABEL_TYPE_ALPHA; game_rank_label = FILERANK_LABEL_TYPE_NUM | FILERANK_LABEL_DESC; game_allow_flip = TRUE; game_doc_about = "Checkers " "Two player game " "Status: Partially implemented (currently unplayable) " "URL: "GAME_DEFAULT_URL("checkers"); } ResultType checkers_who_won (Pos *pos, Player player, char **commp) { static char comment[32]; char *who_str [2] = { "white won", "black won"}; int found_w = 0, found_b = 0; int i; for (i=0; iboard[i])) found_w = 1; else if (CHECKERS_ISBLACK (pos->board[i])) found_b = 1; if (!found_b) { strncpy (comment, who_str[0], 31); *commp = comment; return RESULT_WHITE; }
  • 9. if (!found_w) { strncpy (comment, who_str[1], 31); *commp = comment; return RESULT_BLACK; } return RESULT_NOTYET; } byte * checkers_movegen (Pos *pos) { int i, j, diffx, diffy; byte movbuf [256]; byte *movlist, *mp = movbuf; byte *board = pos->board; Player player = pos->player; for (i=0; iboard [j * board_wid + i]) { case CHECKERS_WK: sum += (5 - fabs ((i-3.5) * (j-3.5)) / 10); break; case CHECKERS_WP: sum += (1 + j / 10.0); break; case CHECKERS_BK: sum -= (5 - fabs ((i-3.5) * (j-3.5)) / 10); break; case CHECKERS_BP: sum -= (1 + (board_heit - 1 - j) / 10.0); break; } } *eval = sum; return RESULT_NOTYET; } static int oldx = -1, oldy = -1; void checkers_reset_uistate () { oldx = -1, oldy = -1; } int checkers_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play,
  • 10. byte **movp, int ** rmovep) { static byte move[10]; byte *mp = move; int diffx, diffy; byte *board = pos->board; if (type != GTKBOARD_BUTTON_RELEASE) return 0; if (oldx < 0) { int val = board [y * board_wid + x]; if ((CHECKERS_ISWHITE(val) && !(to_play == WHITE)) || (CHECKERS_ISBLACK(val) && !(to_play == BLACK))) return -1; oldx = x; oldy = y; return 0; } if (x == oldx && y == oldy) { oldx = -1; oldy = -1; return 0; } diffx = x - oldx; if (abs (diffx) == 1) { diffy = y - oldy; if (abs (diffy) != 1) { oldx = oldy = -1; return -1;} if (!CHECKERS_ISKING(board [oldy * board_wid + oldx]) && diffy != (to_play == WHITE ? 1 : -1)) { oldx = oldy = -1; return -1;} if (board [y * board_wid + x] != 0) { oldx = oldy = -1; return -1;} *mp++ = oldx; *mp++ = oldy; *mp++ = 0; *mp++ = x; *mp++ = y; if ((to_play == WHITE && y == board_heit - 1)
  • 11. || (to_play == BLACK && y == 0)) *mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK); else *mp++ = board [oldy * board_wid + oldx]; *mp++ = -1; *movp = move; oldx = oldy = -1; return 1; } if (abs (diffx) == 2) { int val; diffy = y - oldy; if (abs (diffy) != 2) { oldx = oldy = -1; return -1;} if (!CHECKERS_ISKING(board [oldy * board_wid + oldx]) && diffy != (to_play == WHITE ? 2 : -2)) { oldx = oldy = -1; return -1;} if (board [y * board_wid + x] != 0) { oldx = oldy = -1; return -1;} val = board [(y-diffy/2) * board_wid + (x-diffx/2)]; if ((!CHECKERS_ISWHITE(val) && (to_play == BLACK)) || (!CHECKERS_ISBLACK(val) && (to_play == WHITE))) { oldx = oldy = -1; return -1;} *mp++ = oldx; *mp++ = oldy; *mp++ = 0; *mp++ = oldx+diffx/2; *mp++ = oldy+diffy/2; *mp++ = 0; *mp++ = x; *mp++ = y; if ((to_play == WHITE && y == board_heit - 1) || (to_play == BLACK && y == 0)) *mp++ = (to_play == WHITE ? CHECKERS_WK : CHECKERS_BK); else *mp++ = board [oldy * board_wid + oldx]; *mp++ = -1; *movp = move; oldx = oldy = -1; return 1;
  • 12. } { oldx = oldy = -1; return -1;} } char ** checkers_get_pixmap (int idx, int color) { int bg; int i; static char pixbuf[CHECKERS_CELL_SIZE * (CHECKERS_CELL_SIZE+1)]; for(i=0, bg=0;i<3;i++) { int col = checkers_colors[i+3]; if (col<0) col += 256; bg += col * (1 << (16-8*i));} return pixmap_ball_gen (CHECKERS_CELL_SIZE, pixbuf, CHECKERS_ISWHITE(idx) ? 0xffffff : 0x0000ff, bg, (idx == CHECKERS_WP || idx == CHECKERS_BP) ? 8 : 12, 24); }