36 #include <inttypes.h> |
36 #include <inttypes.h> |
37 #include <sys/select.h> |
37 #include <sys/select.h> |
38 #include <stdio.h> |
38 #include <stdio.h> |
39 #include <errno.h> |
39 #include <errno.h> |
40 |
40 |
41 static const uint8_t boardx = 10, boardy = 10; |
41 static const uint8_t boardx = 4, boardy = 10; |
42 static int inputy = 21; /* should be overridden on game startup */ |
42 static int inputy = 21; /* should be overridden on game startup */ |
43 |
43 |
44 static int timecontrol(GameState *gamestate, GameInfo *gameinfo) { |
44 static int timecontrol(GameState *gamestate, GameInfo *gameinfo) { |
45 if (gameinfo->timecontrol) { |
45 if (gameinfo->timecontrol) { |
46 uint16_t white = remaining_movetime(gameinfo, gamestate, WHITE); |
46 uint16_t white = remaining_movetime(gameinfo, gamestate, WHITE); |
110 mvaddch(boardy+1, x, 'a'+i); |
110 mvaddch(boardy+1, x, 'a'+i); |
111 mvaddch(y, boardx-2, '1'+i); |
111 mvaddch(y, boardx-2, '1'+i); |
112 } |
112 } |
113 |
113 |
114 /* move log */ |
114 /* move log */ |
115 // TODO: introduce window to avoid bugs with a long move log |
115 uint8_t logy = 2; |
116 uint8_t logy = 1; |
116 const uint8_t logx = boardx + 28; |
117 const uint8_t logx = boardx + 30; |
117 move(logy, logx); |
118 int logi = 1; |
118 |
|
119 unsigned int logi = 0; |
119 MoveList *logelem = gamestate->movelist; |
120 MoveList *logelem = gamestate->movelist; |
120 |
121 |
|
122 /* wrap log after 45 moves */ |
|
123 while (gamestate->movecount/6-logi/3 >= 15) { |
|
124 logelem = logelem->next->next; |
|
125 logi++; |
|
126 } |
|
127 |
121 while (logelem) { |
128 while (logelem) { |
122 logi++; |
129 _Bool iswhite = (logelem->move.piece & COLOR_MASK) == WHITE; |
123 if (logi % 2 == 0) { |
130 if (iswhite) { |
124 if ((logi - 2) % 4 == 0) { |
131 logi++; |
125 logy++; |
132 printw("%d. ", logi); |
126 move(logy, logx); |
|
127 } |
|
128 printw("%d. ", logi / 2); |
|
129 } |
133 } |
130 |
134 |
131 addstr(logelem->move.string); |
135 addstr(logelem->move.string); |
132 if (!logelem->next) { |
136 if (!iswhite && logi%3 == 0) { |
133 if (gamestate->stalemate) { |
137 move(++logy, logx); |
134 addstr(" stalemate"); |
138 } else { |
135 } |
139 addch(' '); |
136 } |
140 } |
137 addch(' '); |
|
138 |
141 |
139 logelem = logelem->next; |
142 logelem = logelem->next; |
140 } |
143 } |
141 } |
144 } |
142 |
145 |