My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
Engine  
Information on the algorithms used in the cathedral game engine
Phase-Design
Updated Nov 8, 2008 by magex9@gmail.com

Introduction

The cathedral engine has a few important methods. This page will describe the algorithms used for a few of these methods.

Details

/**
 * A interface that could be the core engine for almost any language.
 * 
 * @author Scott Finlay
 *
 */
public interface CathedralEngine {

        /**
         * Get a set of the available peices to play.
         * 
         * Can be used to determine whats left at the end of the game.
         */
        public Set<Peice> getAvaliablePeices();

        /**
         * Start a new game, reset everything.
         */
        public void reset();

        /**
         * A list of the history moves.
         * 
         * "WCAwF5,BINnA3*,WBRwE1!" where * means a capture, and ! means game over
         * @return a list of the moves.
         */
        public List<Move> getHistory();

        /**
         * Check to see if the move is valid.
         * 
         * Used for doing stuff when hovering above squares to highlight them,
         * and can be used rapidly.
         * 
         * @return true if its a valid move
         */
        public boolean isValidMove(Peice peice, String square, String orientation);

        /**
         * Validates the move then plays the peice
         * 
         * @return true if peice captured
         */
        public boolean move(Peice peice, String square, String orientation) throws InvalidMoveException;

        /**
         * Check to see if the game is over
         * 
         * @return true if the game is over
         */
        public boolean isGameOver();

}

isValidMove(peice, square, orientation)

A few steps need to happen to get it to work.

  1. Check to make sure all the requested squares are free
    • Check to make sure another peice isnt in the square
    • Check to make sure the oponent doesnt control that section

move(peice, square, orientation)

  1. Check to make sure the move is valid
    • Throw a new InvalidMoveException if its not valid
  2. Mark all squares as taken by that peice.
  3. Do a breadth first search to find all loops of peices of the given color.
    • Start on the north square
    • Find all adjacent squares with the same color of square or an edge.
    • Do this until you get to
      • A peice that was part of the peice played, then return this path in the set of paths.
      • A dead end (no more peices that havnt been visited).
  4. For each path, get a list of all peices that are inside it.
    • Loop through all rows and find the most east and west check every other peice on the board and see if they fall inbetween all those, do the same for the columns. If a peice is in between every combination then its in the middle.
    • If only 1 peice that is not yours is inside it the remove that peice
    • Mark all the squares inside the current players color
Powered by Google Project Hosting