Class Move

java.lang.Object
ubc.team09.state.Move

public class Move extends Object
This class is used to handle moves on the board. Use this class to encode or decode moves as ints and check their validity.
The section below describes how moves are encoded as ints, but you don't need to understand those details to use the class.

Representation of Moves

A move can be represented with three values:
  • The position of the queen we want to move,
  • The queen's new position, and
  • The position of the queen's arrow.

Since these are all position indices, they can be represented by something as small as a byte. To ensure we have the convenience of using primitive values, we will represent these three values with a single int, where the bits are used like so:
  • The first (least significant) 8 bits are the starting position of the queen.
  • The next 8 bits are the queen's destination.
  • The next 8 bits are the target for the queen's arrow.
  • The remaining (most significant) 8 bits indicate which player made the move. This could be deduced from other board state information (i.e., checking which queen position array the starting position belongs to), but we're not using these bits for anything else so we might as well store the player color for convenience.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Represents a null move.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte
    arrow(int move)
    Reads the position where the queen fires an arrow from a move.
    static int
    encode(byte start, byte end, byte arrow, byte player)
    Encodes a move as an integer.
    static byte
    end(int move)
    Reads the ending position (of the queen) from a move.
    static boolean
    isLegal(BoardState board, int move)
    Returns true if and only if a move is legal from a given board state.
    static boolean
    isLegal(State board, int move)
    Returns true if and only if a move is legal from a given board state.
    static byte
    player(int move)
    Reads the active player from a move.
    static byte
    start(int move)
    Reads the starting position (of the queen) from a move.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Move

      public Move()
  • Method Details

    • encode

      public static int encode(byte start, byte end, byte arrow, byte player)
      Encodes a move as an integer.
      Parameters:
      start - The starting position index (0-99) of the queen to move.
      end - The position index the queen will move to.
      arrow - The position index where the queen will fire her arrow after moving.
      player - The player making the move (0 for White, and 1 for Black).
      Returns:
      An integer representation of the move.
    • start

      public static byte start(int move)
      Reads the starting position (of the queen) from a move.
      Parameters:
      move - The integer representation of a move. See encode(byte, byte, byte, byte)
      Returns:
      A position index.
    • end

      public static byte end(int move)
      Reads the ending position (of the queen) from a move.
      Parameters:
      move - The integer representation of a move. See encode(byte, byte, byte, byte)
      Returns:
      A position index.
    • arrow

      public static byte arrow(int move)
      Reads the position where the queen fires an arrow from a move.
      Parameters:
      move - The integer representation of a move. See encode(byte, byte, byte, byte)
      Returns:
      A position index.
    • player

      public static byte player(int move)
      Reads the active player from a move.
      Parameters:
      move - The integer representation of a move. See encode(byte, byte, byte, byte)
      Returns:
      0 for White, and 1 for Black.
    • isLegal

      public static boolean isLegal(State board, int move)
      Returns true if and only if a move is legal from a given board state.
    • isLegal

      public static boolean isLegal(BoardState board, int move)
      Returns true if and only if a move is legal from a given board state.