121 } |
121 } |
122 printw("%d. ", logi / 2); |
122 printw("%d. ", logi / 2); |
123 } |
123 } |
124 |
124 |
125 if (logelem) { |
125 if (logelem) { |
126 Move move = logelem->move; |
126 addstr(logelem->move.string); |
127 if ((move.piece&PIECE_MASK) == KING && |
|
128 abs(move.tofile-move.fromfile) == 2) { |
|
129 addstr(move.tofile==fileidx('c')?"O-O-O":"O-O"); |
|
130 } else { |
|
131 char logstr[] = { |
|
132 getpiecechr(move.piece), |
|
133 filechr(move.fromfile), rowchr(move.fromrow), |
|
134 move.capture ? 'x':'\0', |
|
135 filechr(move.tofile), rowchr(move.torow), |
|
136 move.check ? '+' : (move.promotion ? '=' : '\0'), |
|
137 move.promotion ? getpiecechr(move.promotion) : '\0' |
|
138 }; |
|
139 for (int stri = 0 ; stri < sizeof(logstr) ; stri++) { |
|
140 if (logstr[stri]) { |
|
141 addch(logstr[stri]); |
|
142 } |
|
143 } |
|
144 } |
|
145 if (!logelem->next) { |
127 if (!logelem->next) { |
146 if (gamestate->checkmate) { |
128 if (gamestate->stalemate) { |
147 addstr("\b#"); |
|
148 } else if (gamestate->stalemate) { |
|
149 addstr(" stalemate"); |
129 addstr(" stalemate"); |
150 } |
130 } |
151 } |
131 } |
152 addch(' '); |
132 addch(' '); |
153 |
133 |
309 } else { |
289 } else { |
310 Move move; |
290 Move move; |
311 int eval_result = eval_move(gamestate, movestr, &move); |
291 int eval_result = eval_move(gamestate, movestr, &move); |
312 switch (eval_result) { |
292 switch (eval_result) { |
313 case VALID_MOVE_SYNTAX: |
293 case VALID_MOVE_SYNTAX: |
314 net_send_data(opponent, NETCODE_MOVE, &move, sizeof(Move)); |
294 net_send_data(opponent, NETCODE_MOVE, &move, |
|
295 sizeof(Move)-8); |
315 code = net_recieve_code(opponent); |
296 code = net_recieve_code(opponent); |
316 move.check = code == NETCODE_CHECK || |
297 move.check = code == NETCODE_CHECK || |
317 code == NETCODE_CHECKMATE; |
298 code == NETCODE_CHECKMATE; |
318 gamestate->checkmate = code == NETCODE_CHECKMATE; |
299 gamestate->checkmate = code == NETCODE_CHECKMATE; |
319 gamestate->stalemate = code == NETCODE_STALEMATE; |
300 gamestate->stalemate = code == NETCODE_STALEMATE; |
405 } else { |
386 } else { |
406 net_send_code(opponent, NETCODE_DECLINE); |
387 net_send_code(opponent, NETCODE_DECLINE); |
407 } |
388 } |
408 break; |
389 break; |
409 case NETCODE_MOVE: |
390 case NETCODE_MOVE: |
410 net_recieve_data(opponent, &move, sizeof(Move)); |
391 net_recieve_data(opponent, &move, sizeof(Move)-8); |
411 code = validate_move(gamestate, &move); |
392 code = validate_move(gamestate, &move); |
412 if (code == VALID_MOVE_SEMANTICS) { |
393 if (code == VALID_MOVE_SEMANTICS) { |
413 apply_move(gamestate, &move); |
394 apply_move(gamestate, &move); |
414 if (move.check) { |
395 if (move.check) { |
415 net_send_code(opponent, NETCODE_CHECK); |
396 net_send_code(opponent, NETCODE_CHECK); |