You are given a game board that contains a four by four (4x4) array of
pieces. The pieces can be one of six shapes and can be one of six colors
If the board contains 4 pieces of the same shape and same color, the board
contains a winning pattern.
public enum Color
{
Red,
Blue,
Green,
Yellow,
Black,
Purple
}
public enum Shape
{
Square,
Triangle,
Circle,
Star,
Pentagon,
Octagon
}
public class Piece
{
public Color color;
public Shape shape;
public bool Equals(Piece compareTo) {};
}
public class Board
{
public Piece[,] position = new Piece[4,4];
public void Board(){ /*completely builds the board*/};
public void MakeRandomBoard(){};
public piece GetPiece(int x) {};
public bool IsWinner() {};
}
Write the code to detect when a winning pattern is present in a board.
---_---------
my solution is to use hashtable to record pieces and counts, if anyone is 4,
return true. for hashtable, i did not give a hash fuction. any idea?
we can also use 6*6 array to record counts.