-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_state.c
More file actions
100 lines (82 loc) · 2.12 KB
/
Copy pathtest_state.c
File metadata and controls
100 lines (82 loc) · 2.12 KB
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
96
97
98
99
100
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "konane.h"
#include "state.h"
#include "utility.h"
int main( void )
{
char board[SIZE][SIZE];
char player1 = 'B';
char player2 = 'W';
int player = 0;
/* populate board */
for( int i = 0; i < SIZE ; i++ )
{
for( int j = 0; j < SIZE; j++ )
{
if( player == 0 )
{
board[i][j] = player1;
player = 1;
}
else
{
board[i][j] = player2;
player = 0;
}
}
if( player == 0 )
player = 1;
else
player = 0;
}
/* create a new state */
struct State * state = new_state( board, player1 );
printf( "Player : %c\n", state->player );
/* print board */
for( int i = 0; i < SIZE ; i++ )
{
for( int j = 0; j < SIZE; j++ )
{
printf( "%c", state->board[i][j] );
}
printf( "\n" );
}
printf( "\n" );
struct State * state2 = new_state( board, player2 );
printf( "Player : %c\n", state2->player );
/* print board */
for( int i = 0; i < SIZE ; i++ )
{
for( int j = 0; j < SIZE; j++ )
{
printf( "%c", state2->board[i][j] );
}
printf( "\n" );
}
/* compare states */
printf( "same = %d\n", compare_state( state, state ) );
printf( "different = %d\n", compare_state( state, state2 ) );
/* remove piece from board */
board[ 3 ][ 3 ] = 'O';
struct State * state3 = new_state( board, player2 );
printf( "Player : %c\n", state3->player );
/* print board */
for( int i = 0; i < SIZE ; i++ )
{
for( int j = 0; j < SIZE; j++ )
{
printf( "%c", state3->board[i][j] );
}
printf( "\n" );
}
/* print state */
print_state( state );
print_state( state2 );
print_state( state3 );
Free( state, sizeof( struct State ) );
Free( state2, sizeof( struct State ) );
Free( state3, sizeof( struct State ) );
return EXIT_SUCCESS;
}