Skip to content

EthanHaid/Chess-App

Repository files navigation

Chess

Desktop chess application in Java

This is a Desktop chess app made using Java. It can be configured to run in User vs User mode, User vs AI, or AI vs AI. The purpose of this project is fundamentally as a coding exercise, specifically for AI If you find yourself tempted to create an AI of your own, I'd welcome that, and I enourage you to build one better than the one I did.

To Create an AI

When creating an AI in this Chess application framework, your AI class must extend Player and implement makeMove() You will want to call executeMove(piece, point) within makeMove(), and you will want to do so relatively quickly. This is not where your AI should do its thinking, that should be done in another thread that you can initialize in the constructor.

Some example method calls:

Point p= new Point(4, 7); //example of creating a point p.x == 4 // this is a true statement

Piece v1 = pieceAt(point); //returns the friendly Piece at Point, null if no friendly piece found boolean v2 = onBoard(point); //returns true if a given Point is on the Board, false otherwise int v3 = getTeam(); //returns your team: 0 for white, 1 for black int v4 = getStartPos(); //returns starting position: 0 for top, 1 for bottom ArrayList v5 = getAlives(); //returns ArrayList of friendly alive pieces ArrayList v6 = getDeads(); //returns ArrayList of friendly dead pieces Point v7 = piece.getTile(); //returns the Point which the piece is on. Player v8 = piece.getPlayer(); //returns returns the player that the piece is a part of (probably won't need this. good AI implimentation wouldn't heheh. go ahead though.)

Player v9 = getOpponent(); //returns your opponent.

//all functions can be called on your opponent too. for example: ArrayList v10 = getOpponent().getAlives(); //returns ArrayList of opposition's alive pieces ArrayList v11 = piece.getPlayer().getOpponent().getAlives(); //returns Arraylist of a piece's opposition's alive pieces (again, probs won't need this.)

if(piece instanceof Pawn) //detects the type of piece if(piece instanceof Rook) //detects the type of piece

executeMove(piece, point); this is the function you must call to make your move. the "piece" parameter is the Piece you want to move, and the "point" is where you want to move it to. valid points are from (0,0) to (7,7)

to perform a castle move, executeMove() the king 2 tiles to the left or right. The program will move the appropriate Rook automatically.

finally, when you feel that your AI is ready for testing, go to GameComponent.java and see lines 36-38. simply modify line 36 to link instead to your AI class to start the program, excecute ChessFrame. it'll drive the rest.

Random things that you probably don't need to know

  • if your AI doesn't call executeMove(), the makeMove() will be called repeatedly until it does.
  • if you call executeMove() multiple times, you're cheating. it would take me all of 30 seconds to disallow that, but i'm lazy.
  • there are other ways of cheating too. don't do them.
  • User.java is the implementation of the person operating the mouse playing the game. The code probably won't be helpful though, there's no game logic there.
  • If you (for some reason) want to call one of the methods within your AI from outside of it, it's more complicated than you think. ask me.

Good luck, amigos!

About

Desktop chess application for developing intelligent state-search algorithms in Java

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages