#include <stdio.h> #define SIZE 3 #define NONE 0 #define MARU 1 #define BATU 2 int board[SIZE][SIZE] = { 0 }; char mark[3][3] = {"-", "○", "×"}; void print_board() { int i, j; for (i = 0; i < SIZE; ++i) { for (j = 0; j < SIZE; ++j) /* line */ printf("+--"); printf("+\n"); for (j = 0; j < SIZE; ++j) /* mark */ printf("|%s", mark[board[j]]); printf("|\n"); } for (j = 0; j < SIZE; ++j) /* line */ printf("+--"); printf("+\n"); } int check_end() { int i, j; for (i = 0; i < SIZE; ++i) for (j = 0; j < SIZE; ++j) if (board[j] == NONE) return 0; return 1; } int valid_position(int x, int y) { return 0 <= x && x < SIZE && 0 <= y && y < SIZE && board[x][y] == NONE; } int main() { int x, y; int player = MARU; printf("<< ○× >>\n"); print_board(); while (!check_end()) { while (1) { printf("Player%d Put[%s] (x, y): ", player, mark[playe[/url]); scanf("%d %d", &x, &y); if (valid_position(x, y)) break; printf("Can't Put. Again.\n"); } board[x][y] = player; /* set mark */ printf("<< ○× >>\n"); print_board(); if (player == MARU) player = BATU; /* change player */ else player = MARU; } printf("Game is Over.\n"); } 下のような実行例にしたいのですが混乱して○と×の位置がおかしくなってしまったので教えてください。 実行例 << ○× >> +--+--+--+ |-|-|-| +--+--+--+ |-|-|-| +--+--+--+ |-|-|-| +--+--+--+ Player1 Put[○] (x, y): 1 1 << ○× >> +--+--+--+ |-|-|-| +--+--+--+ |-|○|-| +--+--+--+ |-|-|-| +--+--+--+ <<中略>> Player2 Put[×] (x, y): 2 1 << ○× >> +--+--+--+ |×|-|-| +--+--+--+ |○|○|×| +--+--+--+ |-|-|-| +--+--+--+ Player1 Put[○] (x, y): 1 2 << ○× >> +--+--+--+ |×|-|-| +--+--+--+ |○|○|×| +--+--+--+ |-|○|-| +--+--+--+ Player2 Put[×] (x, y): 1 2 Can't Put. Again. << ○× >> +--+--+--+ |×|-|-| +--+--+--+ |○|○|×| +--+--+--+ |-|○|-| +--+--+--+ Player2 Put[×] (x, y): 1 0 << ○× >> +--+--+--+ |×|×|-| +--+--+--+ |○|○|×| +--+--+--+ |-|○|-| <<中略>> Player2 Put[×] (x, y): 0 2 << ○× >> +--+--+--+ |×|×|○| +--+--+--+ |○|○|×| +--+--+--+ |×|○|-| +--+--+--+ Player1 Put[○] (x, y): 2 2 << ○× >> +--+--+--+ |×|×|○| +--+--+--+ |○|○|×| +--+--+--+ |×|○|○| +--+--+--+ Game is Over.
○×ゲームで…
○×ゲームで…
Re:○×ゲームで…
void print_board(void)
のところの、
printf("|%s", mark[board[j]]);
を、
printf("|%s", mark[board[j]]);
にするだけでいいのではないでしょうか。
のところの、
printf("|%s", mark[board[j]]);
を、
printf("|%s", mark[board[j]]);
にするだけでいいのではないでしょうか。