-
Notifications
You must be signed in to change notification settings - Fork 0
/
chess.c
95 lines (84 loc) · 1.39 KB
/
chess.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdlib.h>
#include <string.h>
#include "chess.h"
GameData Gamestate;
main()
{
Dudes *Board[8][8];
CreateBoard(Board);
SetupBoard(Board);
while (1)
{
TakeTurn(Board);
}
}
void TakeTurn(Dudes *Board[8][8])
{
GetMove(Board);
NextTurn();
}
void NextTurn()
{
if (Gamestate.Turn == white)
{
Gamestate.Turn = black;
}
else
{
Gamestate.Turn = white;
}
}
void CreateBoard(Dudes *Board[8][8])
{
Gamestate.White.CastleLeft =
Gamestate.White.CastleRight =
Gamestate.Black.CastleLeft =
Gamestate.Black.CastleRight = false;
Gamestate.Turn = white;
int i, j;
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
Board[i][j] = malloc(sizeof(Dudes));
}
}
}
void SetupBoard(Dudes *Board[8][8])
{
int x, y;
for (y = 0; y < 8; y++)
{
for (x = 0; x < 8; x++)
{
switch (y)
{
case 1 : Board[x][y]->Piece = pawn;
case 0 : Board[x][y]->Colour = white;
break;
case 6 : Board[x][y]->Piece = pawn;
case 7 : Board[x][y]->Colour = black;
break;
}
if (y == 0 || y == 7)
{
switch (x)
{
case 0 :
case 7 : Board[x][y]->Piece = rook;
break;
case 1 :
case 6 : Board[x][y]->Piece = knight;
break;
case 2 :
case 5 : Board[x][y]->Piece = bishop;
break;
case 3 : Board[x][y]->Piece = queen;
break;
case 4 : Board[x][y]->Piece = king;
break;
}
}
}
}
}