Using C language Simple implementation of the board for 5*5 Gobang Games, the following is the source code:
#include <stdio.h> #include <stdlib.h>//initialization of an array void init (Char arr[5][5]) //arr array size can change the checkerboard size { int i = 0, j = 0; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { arr[i][j] = ' '; } }}//print Checkerboard Void print_cheseboard (char arr[][5]) { int i = 0; for (i = 0; i < 5; i++) { printf ("| %c | %c | %c | %c | %c |\n ", arr[i][0], arr[i][1], arr[i][2], arr[i][3], arr[i] [4]); if (i != 4) { printf ("|---|---|---|---|---|\n"); } }}//player Chess Void player_move (char arr[][5]) { int x = 0; int y = 0; printf ("Please enter coordinates >>> \n"); &NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d%d", &x, &y); x -= 1; y -= 1; if ( arr[x][y] == ' ') { arr[x][y] = ' x '; } else { printf ("Input error, please re-enter: \ n"); player_move (arr); }}//Computer chess void computer_ Move (char arr[][5]) { int i = 0, j = 0; for (i = 0; i < 5; i++) { for (j = 0; j < 5; j++) { if (arr[i][j] == ' ') break; } if (arr[i][j] == ' ') break; } if (i*j == 25) exit (0); else arr[i][j] = ' 0 ';} Battle Judgment Char check (Char arr[][5]) { int i = 0; for (i = 0; i < 5; i++) { if (Arr[i][0] == arr[i][1] && arr[i][1] &NBSP;==&NBSP;ARR[I][2]&NBSP;&&&NBSP;ARR[I][2]&NBSP;==&NBSP;ARR[I][3]&NBSP;&&&NBSP;ARR[I][3] &NBSP;==&NBSP;ARR[I][4]) { if (arr[i][0] != ' ') &NBSP;&NBSP;&NBSP;&Nbsp; return arr[i][0]; } } for (i = 0; i < 5; i++) { if (arr[0][i] == arr[1][i] && arr[1][i] == arr[2][i] & & arr[2][i] == arr[3][i] && arr[3][i] == arr[4][i]) { if (arr[0][i] != ' ') return arr[0][i]; } } if (arr[0][0] == arr[1][1] && arr[ 1][1] == arr[2][2] && arr[2][2] == arr[3][3] && arr[3][3] == arr[ 4][4]) { if (arr[0][0] != ' ') return arr[0][0]; } if (arr[0][4] == arr[1][3] && arr[1][3] == arr[2][2] && arr[2][2] == arr[3][1] && arr[3][1] == arr[4][0]) { if (arr[0][4] != ' ') return arr[0][4]; } return ' ';} Main function Int main () { char done= ' '; char arr[5][ 5]; iNIT (arr); do { print_cheseboard (arr); player_move (arr); done = check (arr); if (done != ' ') { break; } computer_move (arr); done = check (arr); } while (done == ' '); if (done == ' X ') { printf ("Player wins!!! \ n "); } else &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;PRINTF ("Computer wins!!!" \ n "); } print_cheseboard (arr); system ("pause"); return 0;}
This article from "Wooden Man" blog, declined reprint!
Simple 5*5, Gobang mini-game