• Post Reply Bookmark Topic Watch Topic
  • New Topic

Building A Checkers Engine in Java  RSS feed

 
Shaun Khundker
Greenhorn
Posts: 9
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to build a checkers engine in Java with an AI using a minimax algorithm and brute force to test out which is better in the context of the checkers engine. However I am having trouble to start building the engine itself. Is there any starting point I could use or any advice to help get me started?
Thanks!
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think you shoul‍d start by writing the algorithms down in words of one syllable. That will make it easier to turn into code.
 
Shaun Khundker
Greenhorn
Posts: 9
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't completely understand what you mean by "writing the algorithms down in words of one syllable". Could you please explain? And also just to clarify, I haven't started building the Checkers game engine yet which is why it would be great to have some starting point.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell just means that you have to describe in simple words what such an engine would look like. That's the starting point.

For instance: "A chess engine needs to be able to play a game of chess. A game of chess consists of a board, pieces and players. Pieces consist of a kind and a color and can be placed on squares on the board. A game operates by asking players in turn for the move they wish to make, checking if the move is valid for that player, and then moving the piece in question, until a player can make no more valid moves".

You can use some of the nouns in that description as names for the classes of your engine. You can use some of the verbs in that description as names for the methods of your classes. Here's a small start:
 
Shaun Khundker
Greenhorn
Posts: 9
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification. Basically what I am trying to build is a Checkers game engine which should be able to play a game of checkers. The game should consist of a checkers board, the pieces and two players (in this case, one will be you and one will be the AI) The pieces will have one kind (there normally is two kinds, man and king, although only one kind is really needed since my tests on the engine will not go that far into one game of checkers). The pieces should be placed on the board. The game operates by asking the first player to move, checking if the move is valid and then actually moving the piece. Then the AI will make a move based on its algorithm (brute force or minimax(alpha-beta pruning)). This will repeat multiple times till the game is complete, but I will probably need to have it to maximum five to six turns as my computer might not be able to handle processing power. I should also be able to test out how many nodes the algorithm has evaluated and how long it took to evaluate and find a good move to make. For a valid move, the rules are here https://www.itsyourturn.com/t_helptopic2030.html .

Hope it explains what I am trying to do. Let me know if I need to clarify anything.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, so first start with the basic workings of a chess game, and don't worry about AIs just yet. Build an application that when given input from two human players, plays a game according to the rules of chess.

You'll need at least Board, Game, Piece and Player classes. I suggest you also add a Piece.Kind enum and a Piece.Color enum.

Think about what the responsibilities of these classes will be, add method declarations and document the behavior of these methods in the way I showed you with the Board class. Don't add fields or implement any methods until you're satisfied with the design.

If you're stuck, post your code here and tell us what you're stuck on.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Great, so first start with the basic workings of a chess game,


Checkers (or draughts, if you're British), not chess.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, I read past that, my bad!

I think most of what I said is still correct though. Instead of a Piece.Kind enum, you might add a boolean property to the Piece class that tells whether a piece is a king.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes, I think it all applies.
I just thought I'd nip it in the bud before any chess-like things started to creep in!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!