-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOLLINSS-reversi1.c
More file actions
82 lines (72 loc) · 2.67 KB
/
COLLINSS-reversi1.c
File metadata and controls
82 lines (72 loc) · 2.67 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
#include <stdio.h>
#include "reversi.h"
/*
* Initialise_Board()
*
* Initialises all squares on board to empty (zero)
* Initialises central positions with two pieces for each player.
* Initialises the scores for each player at two points each
*/
void Initialise_Board(void) {
int row, col;
for (col = 0; col <= size; col++) { /*loops through the columns first*/
for (row = 0; row < size; row++) { /*loops through the rows after*/
/* sets the board to the starting state depending on "size" */
if ((col == (size / 2) && row + 1 == (size / 2)) || (col == ((size / 2) + 1) && row + 1 == ((size / 2) + 1))) {
board[col][row] = PLAYER2;
} else if ((col == ((size / 2) + 1) && row + 1 == size / 2) || (col == size / 2 && row + 1 == ((size / 2) + 1)))
board[col][row] = PLAYER1;
else
board[col][row] = EMPTY_SPACE;
}
}
player1_score = 2;
player2_score = 2;
}
/*
* Print_Board()
*
* Prints the board to the screen in the format given in the assignment sheet
*/
void Print_Board(void) {
int col, row;
fprintf(stdout,"\n");
fprintf(stdout," ");
/* ensures the board is of the correct format */for (col = 1; col <= size; col++) {
if (col < 9) {
if (col != size)
fprintf(stdout,"%i ", col);
else if (col == size)
fprintf(stdout,"%i", col);
} else
fprintf(stdout,"%i", col);
}
fprintf(stdout,"\n");
fprintf(stdout," "); /* formatting */
for (col = 1; col <= size; col++) {
fprintf(stdout,"_ ");
}
fprintf(stdout,"\n");
for (row = 0; row < size; row++) {
for (col = 0; col <= size; col++) {
if (col == 0) {
if ((row + 1) < 10)
fprintf(stdout," %i: ", row + 1);
else
fprintf(stdout,"%i: ", row + 1);
} else if (col != 0 && col <= size) {
if (board[col][row] == PLAYER1)
fprintf(stdout,"O ");
else if (board[col][row] == PLAYER2) {
fprintf(stdout,"* ");
} else
fprintf(stdout,". ");
}
}
fprintf(stdout,"\n");
}
fprintf(stdout,"\n");
/* prints off the current score of player1 and player 2 */
fprintf(stdout,"Player 1 (O) score: %i\n", player1_score);
fprintf(stdout,"Player 2 (*) score: %i\n", player2_score);
}