Data structure & algorithm
GAME OF GOMOKU Description: A game board is a square of size N*N (N = 20) of cell Each cell may contain X or O or nothing (non-occupied). Two opposite players: One plays the symbol X, an other plays the symbol O. One after the other: put it symbol into a non-occupied cell on the game board Condition to win: the first player having 5 X (XXXXX) or 5 O (OOOOO) in a row, column, or diagonal without consider the bounderies of opposite. (OXXXXXO is also a win case for X) Heuristic algorithm: For each round, try to put its symbol into the best possible of non-occupied cell The cell is selected by level of priority: 1: Attack if it could create a line of 5 consecutive symbols non-bounded both bounds 2: Defense if the opposite has 4 consecutive symbols one-bounded or 5 nonconsecutive symbols with or without bounded 3: Attack if it could create a line of 4 symbols (consecutive without any bound, nonconsecutive without any bound, consecutive with one-bounded, non-consecutive with one-bounded) 4: Defense if the opposite has 3 symbols ( consecutive without any bound, nonconsecutive without any bound, consecutive with one-bounded, non-consecutive with one-bounded) 5: Attack if it could create a line of 4 (one-bounded) + a line of 3 without any bound 6: Defense if it could create a bound for a line of 4 + a line of 3 7: Attack if it could create 2 lines of 3 without any bound The same principle for line of 3, 2, 1 symbols... Requirements: Define class of Cell and class of Gomoku containing objects of the class Cell Define a method to load a game from a text file naming "C:\\gomoku.txt" (this file contains 20 lines, on each line there are 20 number: either 0, or 1, or 2. 0 means the cell is nonoccupied, 1 for O symbol, 2 for X symbol) Define a method to write a game to a text file naming "C:\\gomoku.txt" (this file contains 20 lines, on each line there are 20 number: either 0, or 1, or 2. 0 means the cell is non-occupied, 1 for O symbol, 2 for X symbol) Define a method to check whether a player wins Define the method play to find the best cell to put your symbol Design a GUI enabling other (program or user) to play the game with your program: a square board of size 20*20, non-editable (see only) a label show your name, non-editable a label show your number of play steps, non-editable a button: if clicked, your program will: load the current board from the file "C:\\gomoku.txt" choose the best cell to fill fill the selected cell and display on the board save the new board into the file "C:\\gomoku.txt"
Test your program to see what is the next cell your program chooses to fill (for symbol O)?
You could also test your program by launch it two times and click on the button of each alternatively: one after the other!