#include <stdio.h>
int plot[8][8];
char *state[] = {"　", "○ ", "● "};
char *hands[] = {"", "先攻", "後攻"};

// prototype
void print_board();

void print_board()
{
  int x, y;
  printf("\033[2J");
  printf("\033[%d;%dH", 0, 0);
  for (y = 0; y < 8; y++) {
    for (x = 0; x < 8; x++) {
      printf("%s|", state[plot[x][y]]);
    }
    printf("\n");
    printf("--+--+--+--+--+--+--+--+\n");
  }
}

int main()
{
  int x, y,hand = 1;
  char buf[100];

  while (1) {
    do {
      print_board();
      printf("hand = %s\n", hands[hand]);
      printf("終了 = q\n" );
      printf("x y = " );
      fgets(buf, 100, stdin);
      if (buf[0]=='q' | buf[0]=='Q') {
        printf("終了します\n" );
        return 0;
      }
      sscanf(buf, "%d%d", &x, &y);
    } while (x < 0 | x > 7 | y < 0 | y > 7);
    if (plot[x][y] == 0) {
      plot[x][y] = hand;
      hand = 3 - hand;
    }
  }

  return 0;
}
