-
Notifications
You must be signed in to change notification settings - Fork 0
/
starter_kit.c
150 lines (129 loc) · 4.95 KB
/
starter_kit.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* ************************************************************************** */
/* */
/* :::::::: */
/* starter_kit.c :+: :+: */
/* +:+ */
/* By: tbruinem <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/03/07 19:20:13 by tbruinem #+# #+# */
/* Updated: 2022/03/11 12:51:28 by tbruinem ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
// ### Initialization Input
// First line: `numberOfCells`
// Next `numberOfCells` lines: 7 space-separated integers:
// - `index` for the cell's index.
// - 6 `neigh` variables, one for each direction, containing the index of a neighboring cell or -1 if is there is no neighbor.
// Next line: An integer `yourColors`
// Next `yourColors` lines: 2 space-separated integers:
// - `index` for the color's index.
// - `maxAmount` for the max amount of pellets of that color.
// Next line: An integer `opponentColors`
// Next `opponentColors` lines: 2 space-separated integers:
// - `index` for the color's index.
// - `maxAmount` for the max amount of pellets of that color.
// ### Input for One Game Turn
// First line: An integer `direction` (between 0 and 5): the direction of gravity.
// Next line: `numberOfValidInsertSlots`
// next `numberOfValidInsertSlots` lines: 2 space-separated integers
// - `column`: the column to use for a PLACE command
// - `cellIndex`: the cell that correspond to the top of the column, according to the current gravity
// Next line: `numberOfNewPellets`
// next `numberOfNewPellets` lines: 4 space-separated integers:
// - `index`: index of the new pellet.
// - `cellIndex`: index of the cell the pellet is currently on.
// - `colorIndex`: index of the pellet's color.
// - `isMine`: 1 if you are the owner of this pellet, 0 otherwise.
// Next line: `numberOfChangedPellets`
// next `numberOfChangedPellets` lines: 2 space-separated integers:
// - `index`: index of the pellet.
// - `cellIndex`: index of the cell the pellet is currently on.
// Next line: `numberOfPelletsInHand`
// next `numberOfPelletsInHand` lines: 1 integer:
// - `colorIndex`: index of the pellet's color.
int main() {
int numberOfCells;
scanf("%d\n", &numberOfCells);
for (int i = 0; i < numberOfCells; i++) {
int index;
int n0,n1,n2,n3,n4,n5;
scanf("%d %d %d %d %d %d %d\n", &index, &n0, &n1, &n2, &n3, &n4, &n5);
}
int numberOfColumns;
scanf("%d\n", &numberOfColumns);
int columns[numberOfColumns];
for (int i = 0; i < numberOfColumns; i++) {
int index, d0, d1, d2, d3, d4, d5;
scanf("%d %d %d %d %d %d %d\n", &index, &d0, &d1, &d2, &d3, &d4, &d5);
}
int yourColors;
// int pellet_types[yourColors * 2];
scanf("%d\n", &yourColors);
for (int i = 0; i < yourColors; i++) {
int colorIndex;
int colorAmount;
scanf("%d %d\n", &colorIndex, &colorAmount);
if (!i)
srand(time(NULL) + colorIndex);
// pellet_types[colorIndex] = true;
}
int opponentColors;
scanf("%d\n", &opponentColors);
for (int i = 0; i < opponentColors; i++) {
int colorIndex;
int colorAmount;
scanf("%d %d\n", &colorIndex, &colorAmount);
// pellet_types[colorIndex] = false;
}
while (true) {
for (int i = 0; i < numberOfColumns; i++) {
columns[i] = false;
}
int color_to_play;
int column_to_play;
int direction;
scanf("%d\n", &direction);
int numberOfValidColumns;
scanf("%d\n", &numberOfValidColumns);
for (int i = 0; i < numberOfValidColumns; i++) {
int column, cellIndex;
scanf("%d %d\n", &column, &cellIndex);
column_to_play = column;
columns[column] = true;
}
int numberOfNewPellets;
scanf("%d\n", &numberOfNewPellets);
for (int i = 0; i < numberOfNewPellets; i++) {
int index, cellIndex, colorIndex, isMine;
scanf("%d %d %d %d\n", &index, &cellIndex, &colorIndex, &isMine);
}
int numberOfChangedPellets;
scanf("%d\n", &numberOfChangedPellets);
for (int i = 0; i < numberOfChangedPellets; i++) {
int index, cellIndex;
scanf("%d %d\n", &index, &cellIndex);
}
int numberOfPelletsInHand;
scanf("%d\n", &numberOfPelletsInHand);
for (int i = 0; i < numberOfPelletsInHand; i++) {
int colorIndex;
char newline;
scanf("%d%c", &colorIndex, &newline);
color_to_play = colorIndex;
}
fflush(stdout);
fflush(stdin);
while (true) {
column_to_play = rand() % numberOfColumns;
if (columns[column_to_play])
break;
}
printf("PLACE %d %d\n", column_to_play, color_to_play);
fflush(stdout);
}
}