Exemple #1
0
        public override int GetHashCode()
        {
            int result = 0;

            foreach (Place place in BackendHelper.GetAllPlaces(dimension))
            {
                result ^= hashValues[place.Column, place.Row, (int)GetPlayer(place)];
            }
            return(result);
        }
Exemple #2
0
        static Board()
        {
            hashValues = new int[maxBoardSize, maxBoardSize, 3];
            Random rand = new Random();

            foreach (Place place in BackendHelper.GetAllPlaces(maxBoardSize))
            {
                hashValues[place.Column, place.Row, (int)Player.None]  = 0;
                hashValues[place.Column, place.Row, (int)Player.White] = rand.Next();
                hashValues[place.Column, place.Row, (int)Player.Black] = rand.Next();
            }
        }
Exemple #3
0
        public List <Move> GetPossibleMoves(Player player)
        {
            List <Move> moves = new List <Move>();

            if (befores[player] > 0)
            {
                //faza I - dostawianie

                foreach (Place destination in BackendHelper.GetAllPlaces(dimension))
                {
                    if (GetPlayer(destination) == Player.None)
                    {
                        moves.Add(new Move(player, null, destination));
                    }
                }
            }
            else
            {
                //faza II - przesuwanie

                foreach (Place source in BackendHelper.GetAllPlaces(dimension))
                {
                    if (GetPlayer(source) == player)
                    {
                        foreach (Place vector in BackendHelper.Vectors.Values)
                        {
                            Place destination = source + vector;

                            if (BackendHelper.IsPlaceValid(destination, dimension))
                            {
                                if (GetPlayer(destination) == Player.None)
                                {
                                    moves.Add(new Move(player, source, destination));
                                }
                            }
                        }
                    }
                }
            }

            return(moves);
        }
Exemple #4
0
        public override int Run(Board board, Player player)
        {
            int result = 0;

            foreach (Place place1 in BackendHelper.GetAllPlaces(board.Dimension))
            {
                int    k;
                Player currentPlayer;
                if (player == board.GetPlayer(place1))
                {
                    currentPlayer = player;
                    k             = 1;
                }
                else if (BackendHelper.SwapPlayer(player) == board.GetPlayer(place1))
                {
                    currentPlayer = BackendHelper.SwapPlayer(player);
                    k             = -1;
                }
                else
                {
                    continue;
                }

                foreach (Place vector in BackendHelper.Vectors.Values)
                {
                    Place place2 = place1 + vector;

                    result += k;

                    while (BackendHelper.IsPlaceValid(place2, board.Dimension) &&
                           board.GetPlayer(place2) == currentPlayer)
                    {
                        result += k;
                        place2  = place2 + vector;
                    }
                }
            }

            return(result);
        }
Exemple #5
0
        public override string ToString()
        {
            string result = "";

            foreach (Place place in BackendHelper.GetAllPlaces(dimension))
            {
                switch (GetPlayer(place))
                {
                case Player.None:
                    result += ' ';
                    break;

                case Player.Black:
                    result += 'B';
                    break;

                case Player.White:
                    result += 'W';
                    break;
                }
            }

            return(result);
        }
Exemple #6
0
        public override bool Equals(object other)
        {
            Board board = other as Board;

            if (board == null)
            {
                return(base.Equals(other));
            }

            if (dimension != board.dimension)
            {
                return(false);
            }

            foreach (Place place in BackendHelper.GetAllPlaces(dimension))
            {
                if (GetPlayer(place) != board.GetPlayer(place))
                {
                    return(false);
                }
            }

            return(true);
        }