Six-in-a-Row Artificial Intelligence Design and Its Implementation Based on Java

We can use java language to design the game of chess on eclipse platform and design a new rule for it : “Six in a Row”, this game is more complex than Five-in-a-Row,and we can add a function of Man-Machine Battle in the program.This paper which based on the practical programming experience introduce the algorithm of the above game. The basic mentality of the algorithm is creating a scoring table and all points of the chessboard are scored by using ergodic method.Finally, the machine will placing the chess in the point which have the highest score.This algorithm is clearly operable, and the machine has a high rate of winning when play with human.


Introduction of the Chess Game
The chess is a game played by two people. The rule of the game which we introduced is very similar to Gobang. Players should choose to play the black or white piece. The first player moves his piece on the board, the other player then moves, and the two players take turns on the board. Once there are six pieces which have same color that has formed a line in the horizontal, vertical, or diagonal directions, then the player who charges above color piece wins.
The rule of the chess game with rule"six in a row" is simple and fair.The first player has no advantage,its complexity is higher than Gobang,and the game process is more interesting.

Overall Introduction
The idea of the algorithm is that the machine scores points on the board at any time. The score is based on the score table.The score table is based on the data of everyone's battle and the six-piece chess design.It takes both offensive and defensive situations into account.The offense has a higher priority.

Set Up Chessboard
A chessboard with a size of 19*19 was drawn using the AWT component in java, and the function buttons were drawn at the same time. We use the filling method to draw the chess pieces.

Judge Method
For judging rules, take horizontal for example,we first set a variable,named "trans"to temporarily store how many chess pieces in same color are in a row.
From the rule we know that, after a chess piece is placed, we should judge from the left 5 squares and right 5 squares of the current position. But the prerequisite is that the chess piece within the bounds.So we firstly write a method to judge whether the chess piece is out of bounds.If so, the cycle ends and the next cycle begins. If there is an adjacent chess piece of the same color, the variable "trans" will increase by 1.If "trans" equals to 6, it means that one side has won. Then it will return the color of the winner.If "trans"is less than 6,(it means that there is one or more chess piece of the other color adjacent to it,which is invalid) the "trans" will reset to zero.For vertical,it is similar to the transverse direction, but it is checked in the Y direction.The diagonal are the same--once we know the correspondence of the abscissa and ordinate.We can easily find the exact expression.
The codes of Judge method:

Conclusion
Basically achieve the required functions of the game,the program can show the chessboard to the player, and can make computer play the game with player,it achieves the final desired effect.
In the future, we will optimize the interface design of the program. Perhaps we can set the chessboard to an antique wood color, thicken the lines, and make the function buttons into physical shapes. We need to improve our algorithm, streamline it, and improve the human-machine algorithm to increase the intelligence of the machine. At the same time, we may be able to increase networking capabilities so that two players can play chess happily even if they are thousands of miles apart.