Пример #1
0
    public void HashMove(List <MoveMarble> moves, PLAYER_COLOR player) //modificar todo el cuerpo
    {
        int piece, zobristKey;

        List <keyposition> rowCols = new List <keyposition>();

        foreach (MoveMarble move in moves)
        {
            PLAYER_COLOR current;
            PLAYER_COLOR next;

            if (!move.CurrentCell.Marble)
            {
                current = PLAYER_COLOR.NONE;
            }
            else if (move.CurrentCell.Marble.isWhite)
            {
                current = PLAYER_COLOR.WHITE;
            }
            else
            {
                current = PLAYER_COLOR.BLACK;
            }

            if (!move.CurrentCell.Marble)
            {
                next = PLAYER_COLOR.NONE;
            }
            else if (move.CurrentCell.Marble.isWhite)
            {
                next = PLAYER_COLOR.WHITE;
            }
            else
            {
                next = PLAYER_COLOR.BLACK;
            }



            for (byte row = 0; row < rows; row++)
            {
                int maxcolumn = spaces[row].Length;

                for (byte column = 0; column < maxcolumn; column++)
                {
                    if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && move.hasToDestroy)
                    {
                        spaces[row][column] = PLAYER_COLOR.NONE;
                    }
                    else if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && spaces[row][column] == player)
                    {
                        spaces[row][column] = PLAYER_COLOR.NONE;
                    }
                    else if (move.NextCell != null && move.NextCell.Row == row && move.NextCell.Column == column && spaces[row][column] == PLAYER_COLOR.NONE)
                    {
                        if (current == PLAYER_COLOR.WHITE && (next == PLAYER_COLOR.BLACK || next == PLAYER_COLOR.NONE))
                        {
                            spaces[row][column] = PLAYER_COLOR.WHITE;
                            rowCols.Add(new keyposition(row, column, spaces[row][column]));
                        }

                        else if (current == PLAYER_COLOR.BLACK && (next == PLAYER_COLOR.WHITE || next == PLAYER_COLOR.NONE))
                        {
                            spaces[row][column] = PLAYER_COLOR.BLACK;
                            rowCols.Add(new keyposition(row, column, spaces[row][column]));
                        }

                        else if (current == next)
                        {
                            spaces[row][column] = current;
                        }
                    }
                }
            }
        }
        rowCols.Add(new keyposition(moves[moves.Count - 1].CurrentCell.Row, moves[moves.Count - 1].CurrentCell.Column, activePlayer));

        //Se modifica mas de una posicion al mismo tiempo asi que hay que hacer un bucle
        for (int i = 0; i < rowCols.Count; i++)
        {
            if (rowCols[i].changedTo == PLAYER_COLOR.BLACK)
            {
                piece = 0;
            }
            else
            {
                piece = 1;
            }

            zobristKey = zobristKeys.GetKey((int)rowCols[i].row, (int)rowCols[i].column, piece);

            hashValue ^= zobristKey;
        }
    }
Пример #2
0
    public void HashMove(List <MoveMarble> moves, PLAYER_COLOR player) //modificar todo el cuerpo
    {
        int[] positionsRow    = new int[moves.Count];
        int[] positionsColumn = new int[moves.Count];

        int posIndex = 0;
        int piece, zobristKey;

        foreach (MoveMarble move in moves)
        {
            bool white = move.CurrentCell.Marble.isWhite;

            for (byte row = 0; row < rows; row++)
            {
                int maxcolumn = spaces[row].Length;

                for (byte column = 0; column < maxcolumn; column++)
                {
                    if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && move.hasToDestroy)
                    {
                        spaces[row][column] = PLAYER_COLOR.NONE;
                    }
                    else if (move.CurrentCell.Row == row && move.CurrentCell.Column == column && spaces[row][column] == player)
                    {
                        spaces[row][column] = PLAYER_COLOR.NONE;
                    }
                    else if (move.NextCell != null && move.NextCell.Row == row && move.NextCell.Column == column && spaces[row][column] == PLAYER_COLOR.NONE)
                    {
                        if (white)
                        {
                            spaces[row][column] = PLAYER_COLOR.WHITE;
                        }
                        else
                        {
                            spaces[row][column] = PLAYER_COLOR.BLACK;
                        }

                        positionsRow[posIndex]    = row;
                        positionsColumn[posIndex] = column;
                        posIndex++;
                    }
                }
            }
        }

        //Se modifica mas de una posicion al mismo tiempo asi que hay que hacer un bucle
        for (int i = 0; i < positionsRow.Length; i++)
        {
            if (player == PLAYER_COLOR.BLACK)
            {
                piece = 0;
            }
            else
            {
                piece = 1;
            }
            zobristKey = zobristKeys.GetKey(positionsRow[i], positionsColumn[i], piece);

            hashValue ^= zobristKey;
        }

        /*
         * int filledRow = 0, position, piece, zobristKey;
         *
         * for (int row = rows - 1; row >= 0; row--)
         * {
         *  if (IsEmptySpace(row, column))
         *  {
         *      spaces[row][column] = player;
         *      filledRow = row;
         *      break;
         *  }
         * }
         *
         * position = filledRow * columns + column;
         * if (player == PLAYER_COLOR.BLACK)
         * {
         *  piece = 0;
         * }
         * else
         * {
         *  piece = 1;
         * }
         *
         * zobristKey = zobristKeys.GetKey(position, piece);
         *
         * hashValue ^= zobristKey;*/
    }