Beispiel #1
0
        /// <summary>
        /// Makes the Bot Jump over other pieces on the Board. This makes the first possible jump detected
        /// </summary>
        /// <param name="oldcol"></param>
        /// <param name="oldrow"></param>
        public void Jumper(int oldcol, int oldrow)
        {
            var realtype = Board.Squares[oldcol, oldrow];

            switch (Board.CanJump(realtype, oldcol, oldrow))
            {
            case 0:
                return;

            case 1:
                Board.MovePiece(realtype, oldcol, oldrow, oldcol + 2, oldrow - 2);

                if (Board.CanJump(realtype, oldcol + 2, oldrow - 2) != 0)
                {
                    //Thread.Sleep(1000);
                    Jumper(oldcol + 2, oldrow - 2);
                }
                return;

            case 2:
                Board.MovePiece(realtype, oldcol, oldrow, oldcol - 2, oldrow - 2);
                if (Board.CanJump(realtype, oldcol - 2, oldrow - 2) != 0)
                {
                    //Thread.Sleep(1000);
                    Jumper(oldcol - 2, oldrow - 2);
                }
                return;

            case 3:
                Board.MovePiece(realtype, oldcol, oldrow, oldcol + 2, oldrow + 2);
                if (Board.CanJump(realtype, oldcol + 2, oldrow + 2) != 0)
                {
                    //Thread.Sleep(1000);
                    Jumper(oldcol + 2, oldrow + 2);
                }
                return;

            case 4:
                Board.MovePiece(realtype, oldcol, oldrow, oldcol - 2, oldrow + 2);
                if (Board.CanJump(realtype, oldcol - 2, oldrow + 2) != 0)
                {
                    //Thread.Sleep(1000);
                    Jumper(oldcol - 2, oldrow + 2);
                }
                return;

            default:
                return;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Picks a Random Place to move to
        /// </summary>
        private void BotPlayer1()
        {
            for (int oldrow = 0; oldrow < Board.Size; oldrow++)
            {
                for (int oldcol = 0; oldcol < Board.Size; oldcol++)
                {
                    if (!Board.IsEmptySquare(oldcol, oldrow) && !Board.NotYourPiece(Type, oldcol, oldrow))
                    {
                        var realtype = Board.Squares[oldcol, oldrow];
                        for (int newrow = 0; newrow < Board.Size; newrow++)
                        {
                            for (int newcol = 0; newcol < Board.Size; newcol++)
                            {
                                if (Board.IsEmptySquare(newcol, newrow) && Board.IsValidMove(realtype, oldcol, oldrow, newcol, newrow))
                                {
                                    try
                                    {
                                        pos.Add(oldcol, oldrow);
                                        pos.Add(newcol, newrow);
                                        OldPosition = pos.First();
                                        NewPosition = pos.Last();
                                        pos.Clear();
                                        BotPositions.Add(OldPosition, NewPosition);
                                    }
                                    catch (Exception)
                                    {
                                        List <KeyValuePair <int, int> > Options = new List <KeyValuePair <int, int> >();
                                        Options.Add(BotPositions[OldPosition]);
                                        Options.Add(NewPosition);
                                        BotPositions.Remove(OldPosition);
                                        BotPositions.Add(OldPosition, Options[rnd.Next(2)]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            var a         = RandomValues(BotPositions);
            var oldCol    = a.Key;
            var oldRow    = a.Value;
            var NewPlaces = BotPositions[a];
            var newCol    = NewPlaces.Key;
            var newRow    = NewPlaces.Value;

            Board.MovePiece(Board.Squares[oldCol, oldRow], oldCol, oldRow, newCol, newRow);
            BotPositions.Clear();
            return;
        }