COSC 4117
Course Project
An intelligent player of King's Court

The goal of this project is to write an intelligent player agent for the game of King's Court.  You will have to produce a program that implements the rules of King's Court and allows any of three agent objects to play a game.  The three game playing agents are
(i) an interface agent that allows a human at the keyboard to make the moves,
(ii) a communication agent that communicates with a remote player to receive moves, and
(iii) an intelligent agent that generates its own moves.

The communication agent allows a game of King's Court to be played across the network.   Two humans could play this way but, for our purposes, the important play will be between two intelligent agents.

You can do this project individually or as a team of two. Near the end of the course, we'll hold a tournament among the intelligent agents to see which team's agent rules the board.

The game: King's Court

King's Court is an abstract strategy boardgame invented by Christopher Wroth and first marketed in 1989.

The game board and starting configuration: King's Court is played on a 8x8 board of 64 squares, often displayed as diamonds. The central area of sixteen squares is called the Court. Each player has twenty four pieces placed on the board in the alternating configuration of Figure 1 to start a game. Every square outside the Court contains a piece. The Court is empty.

Figure 1

Movement of pieces: There are two kinds of moves - slides and jumps.

A piece can move by sliding in any direction (vertical or horizontal) to an adjacent square.  A piece cannot slide to a square already occupied.

A piece can also move by jumping (also in any direction, horizontal or vertical) over another piece of either colour on an adjacent square into the next adjacent square in the same direction. That destination square must be unoccupied. If the piece that has been jumped over is the same colour as the jumping piece, it is uneffected; if the piece jumped over is the opposite colour, it is removed from the board. If, from this new position, the piece can make another similar jump in any direction except returning to its previous position, the move can continue for two or more jumps. The move ends when no further jumps can be made or when the player chooses not to make an available jump.

Clarification of rule concerning legal jump sequences: to prevent players making 'null' moves (moves that do not change the configuration of the gameboard at all), a jump cannot contain a sequence that passes through a square more than once if all the intervening jumps go over the player's own tokens. For example, the jump 'A1A3A1' is illegal because the token on A2 belongs to the same player. Another example: the jump 'A1A3C3C1A1' is illegal if the tokens on A2, B3, C2, B1 all belong to the jumping player. If any of these four tokens belongs to the opponent, the jump is legal.

Moves cannot contain any subsequence that does not alter the state of the gameboard. The intent of this rule is to prevent players generating arbitrarily long strings to attempt to crash an opponent's communication agent. Hence 'A1A3' is a legal move even when A2 belongs to the jumping player, but 'A1A3A1A3' and 'A1A3A1A3A1A3A1A3A1A3' are not legal.

Beginning play: One player begins by sliding a piece into the Court. This move cannot be a jump. The second player then makes a first move by sliding a piece into the opposite side of the Court. This also cannot be a jump. The players each make one more slide. Thereafter, the players take turns making any legal move, slide or jump.

Clarification: At the first move, a first player has eight possible slides, two 'up' from the bottom of the board, two 'left', two 'down' and two 'right'. The second player must respond with a move in the opposite direction: 'up' <->'down', 'left'<->'right'. For example, if the first player slides 'B4C4', the second player must respond with 'G4F4' or 'G6F6'.

Goal of the game: After the first moves by each player, both must keep a least one piece in the Court at all times. The first player to have no pieces in the Court loses the game.

Clarification: a player also loses if unable to make a legal move. If a player has one piece in the Court, the player cannot move the piece out of the court. If a player has one piece in the Court,and makes a series of jumps with that piece that take it temporarily outside the Court, the player does not lose, as long as the piece is back in the Court at the end of the jump sequence and the move has not been a null move as defined above.

The program of the game

I am assuming you will be writing your code in Java. If you want to use another language, that is fine but you will be unsupported and it is your responsibility to make the communication work between your program and other players' programs.

Your program should be organized with an environment class called KingsCourt and three player agent classes called: AgentHCI to handle keyboard entry of moves, AgentComm to handle communication with another program and AgentIntelligent to be the artificially intelligent player. It's probably best to make the three classes extend an abstract Agent class.

The game board will be labelled as in the figure (1-8 by A-H).  A board position is specified by an uppercase letter then a digit, e.g. D7.  A turn is specified as a character String indicating the starting position, possibly some intermediate positions and a final position.   For example, "G5F5" specifies that the orange piece at G5 is sliding horizontally to F5. A jump is specified the same way, for example, "A4C4". A multiple jump move adds more pairs to specify the actual path of the jump, for example "B6B4D4". By convention, the player with a token on square "A1" in the starting configuration makes the first move.

The project

The project will proceed in stages as indicated below in the marking scheme.  At each stage you will submit part of the project and I will make suggestions to keep your work on track.  Note that the game environment class must show a display of the current state of the game but there are NO marks for fancy graphics.  Arrays of text characters scrolling by in a console window are just as good as a fancy-frame based animated board.

The tournament, schedule and results

In the tournament (Stage 4), each team will play every other team twice, playing first (piece on A1) once and playing second once.  A win is worth 1 point; a loss gets 0. If a team defaults a game, it receives a score of 0 and the opponent gets 1. A team defaults if (i) it is not at the agreed location at the agreed time ready with a working program, (ii) the team's program crashes during the game, (iii) the team's program makes an illegal move, (iv) the program exceeds the time allowed to complete its moves (to be arranged), or (v) the tournament judge (me) declares a default for some other reason. One possibility is that I may have to call a default on two teams (both getting 0) if they get into a stalemate condition where they continue making moves indefinitely without trying to force each other from the Court.

I have decided to implement this condition. Please set the count of 'maximum moves since last jump that removes an opponent's piece' to 50 and count moves by either player. If a 51st move is made without a capturing jump, the match is forfeited by both teams. For example, if player A makes a jump taking a token from player B then each player makes 25 moves without taking a token, player B's 26th move (51 total moves) must capture a piece from player A or the game is forfeited.

The marking scheme

The project proceeds in stages. I strongly suggest you keep a journal of your ideas and testing as you proceed. Read carefully what is required in the write-up on Dec. 1 so you can start now by keeping the information you need to prepare the document. The submission at the end is worth 50% of the project mark so don't leave it all to the last crazy week of classes!

Stage 1:

Monday, Sept. 25 (5% of project mark)

Submit on one sheet of paper:
  • Team name
  • Member(s) of the team
  • Description of the data structure you propose to track the state of the game - essentially, the instance variables of the KingsCourt game class.

Stage 2:

Friday, Oct. 20 (10% of project mark)

At this point the program should be working with 'interface' and 'communication' players complete and a stub of an AI player. For this stage, collaboration is the way to go.  Work with other class members to get Environments working, and working cooperatively.  This file, TCPComm.java, contains a sample class for communication by TCP in Java.  Submit 
  • a printed listing of the code of your program
  • a list of trial games you have played with other class members to assure your program communicates properly and correctly maintains the state of the game, including determining when a game is complete and which player has won. Temporarily set the number of moves before a draw to a low value and test that the program correctly identifies a draw. Be sure that both games determine the same winner (or a draw) in the same number of moves. THIS IS THE TIME TO IDENTIFY AND CLARIFY ANY AMBIGUITIES IN THE DEFINITIONS THAT WILL BE CRITICAL IN THE TOURNAMENT.

Stage 3:

Wednesday, Nov. 3 (10% of project mark)

At this point, your AI agnet should have, at least, a basic search algorithm implemented. Submit
  • a listing of your AI player class

Stage 4:

November 20-24 (25% of project mark)

Your program should be ready to compete in the course game tournament.  During the week of November 20-24, games will be scheduled and played to determine the agents who make the playoffs.  The tournament format will be decided well in advance, once I have an idea of how many teams will be competing, how long games take to play and so on. Marks out of 25 will be based on tournament standings.  A team that completes all matches without defaulting gets a minimum of 16. Tournament results.
On November 29, a tournament playoff will determine the grand champion; the champion gets 25.

Stage 5:

Friday,  Dec. 1 (50% of project mark)

Submit your final report consisting of the following.
  • printout of source code for your complete program - environment plus players
  • source and compiled executable code on a CD.
  • description (approximately 1000-2000 words plus diagrams if required) of your AI player's intelligence.  I will be evaluating your player based on how you have incorporated a variety of techniques including any or all of: (i) appropriate data structures, (ii) classical AI techniques such as search, (iii) creative heuristic techniques, (iv) 'tuning' based on testing of the intelligent agent against AI and human opposition.  I will also be looking for a critique of your agent: what did it do well; what did it do badly?  The best way to organize the description would be to start with data structures and classic techniques then describe your own creative ideas, then the refinements you did during testing and competition and finish off with the critique of the strengths and weaknesses.