예제 #1
0
        public override void AddCells(Board board, Cell cell, connectedCells c)
        {
            switch(c)
            {
                case connectedCells.north:
                    for (int i = 1; i < connectR; i++)
                    {
                        cells.Add(board.getCell(cell.getRow() - i, cell.getColumn()));
                    }

                    cell.AddConnectedCells((int)connectedCells.north, cells);

                    break;

                case connectedCells.south:
                    for (int i = 1; i < connectR; i++)
                    {
                        cells.Add(board.getCell(cell.getRow() + i, cell.getColumn()));
                    }

                    cell.AddConnectedCells((int)connectedCells.south, cells);

                    break;
            }
        }
예제 #2
0
        //Initial board creation
        public Board(int x, int y, int r)
        {
            length = x;

            width = y;

            connectR = r;

            board = new Cell[length, width];

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    Cell cell = new Cell(i, j);

                    if (i == length - 1)
                    {
                        cell.isPlayable(true);
                    }

                    board[i, j] = cell;
                }
            }
        }
예제 #3
0
파일: Cell.cs 프로젝트: moconno/ConnectFour
 //Copy Constructor
 public Cell(Cell cell)
 {
     rowPos = cell.rowPos;
     colPos = cell.colPos;
     playable = cell.isPlayable();
     state = cell.state;
     connectCells = new SortedDictionary<int, List<Cell>>();
     observers = new SortedDictionary<int, HashSet<Cell>>();
 }
예제 #4
0
        //Copy constructor
        public Board(Board b)
        {
            length = b.GetLength();

            width = b.GetWidth();

            connectR = Board.GetConnectR();

            board = new Cell[length, width];

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    Cell cell = new Cell(b.getCell(i, j));

                    board[i, j] = cell;
                }
            }
        }
예제 #5
0
        public GameState(State s, Board b, Player p, GameState parent, Cell c, Boolean mp)
        {
            maxPlayer = mp;
            state = s;
            cell = c;
            board = b;
            player = p;
            this.parent = parent;
            children = new List<GameState>();
            Region.findConnectedCells(b);
            b.UpdateCellObservers();

            if(MiniMaxTree.TerminalTest(cell) && state != GameState.State.initial)
            {
                state = GameState.State.terminal;

                if (maxPlayer)
                {
                    heuristicValue = MiniMaxTree.MIN_VALUE;
                }
                else
                    heuristicValue = MiniMaxTree.MAX_VALUE;
            }
        }
예제 #6
0
        //Tests the cell played if it is terminal
        public static Boolean TerminalTest(Cell cell)
        {
            int connectR = Board.GetConnectR();

            int key = 0;

            foreach(KeyValuePair<int, List<Cell>> c in cell.GetConnectedCells())
            {
                if(c.Key < 4)
                {
                    key = key + 4;
                }
                else
                    key = key - 4;
                //initialized at 1 because cell has the state we are looking for
                int stateCount = 1;

                //the terminal state belongs to the this cell's connectedCells
                if (c.Value.Count == connectR - 1)
                {
                    foreach (Cell k in c.Value)
                    {
                        if (k.getState().Equals(cell.getState()))
                        {
                            stateCount++;
                        }
                    }

                    //The cell last played created a connect R.  Game over.
                    if (stateCount == connectR)
                    {
                        return true;
                    }
                }

                //Terminal case may belong with observer
                else
                {
                    foreach(Cell k in c.Value)
                    {
                        if(k.GetConnectedCells(key).Count == connectR - 1)
                        {
                            foreach(Cell m in k.GetConnectedCells(key))
                            {
                                if(m.getState().Equals(cell.getState()))
                                {
                                    stateCount++;
                                }

                                //The cell last played created a connect R.  Game over.
                                if (stateCount == connectR)
                                {
                                    return true;
                                }
                            }
                        }
                    }

                }
            }

            return false;
        }
예제 #7
0
파일: Cell.cs 프로젝트: moconno/ConnectFour
        public void AddObserver(int index, Cell cell)
        {
            if (observers.ContainsKey(index))
            {
                if(cell.state.Equals(CellState.empty))
                {
                    if(cell.isPlayable())
                    {
                        observers[index].Add(cell);
                        return;
                    }
                }

                if (this.state.Equals(CellState.empty))
                {
                    //this giving me problems - not evaluating correclty
                    //if(cell.isPlayable())
                    {
                        observers[index].Add(cell);
                        return;
                    }
                }

                if(cell.state.Equals(this.state))
                {
                    observers[index].Add(cell);
                    return;
                }

            }

            //Dictionary Doesn't contain key
            else
            {
                if (cell.state.Equals(CellState.empty))
                {
                    //this giving me problems - not evaluating correctly
                    if(cell.isPlayable())
                    {
                        HashSet<Cell> c = new HashSet<Cell>();
                        c.Add(cell);
                        observers.Add(index, c);
                        return;
                    }
                }

                if (this.state.Equals(CellState.empty))
                {
                    //this giving me problems - not evaluating correctly
                    //if (cell.isPlayable())
                    {
                        HashSet<Cell> c = new HashSet<Cell>();
                        c.Add(cell);
                        observers.Add(index, c);
                        return;
                    }
                }

                if (cell.state.Equals(this.state))
                {
                    HashSet<Cell> c = new HashSet<Cell>();
                    c.Add(cell);
                    observers.Add(index, c);
                    return;
                }
            }
        }
예제 #8
0
 public abstract void AddCells(Board board, Cell cell, connectedCells c);