Example #1
0
        //Just for testing the to-be dll:
        static void Main()
        {
            //Stopwatch stopwatch = Stopwatch.StartNew();

            var Boardy      = new Board(new StdChessStartState());
            var aa          = new pos(3, 3);
            var TestFigure  = new Pawn(Boardy.state, new pos(2, 1), Color.black);
            var TestFigure2 = new Pawn(Boardy.state, new pos(2, 6), Color.white);
            var bb          = new Lpos();
            var cc          = new Lpos();

            for (int i = 0; i < 1; i++)
            {
                bb = TestFigure.PossibleFieldsToMove();
                cc = TestFigure2.PossibleFieldsToMove();
            }
            var jj = Boardy.state;

            jj[3, 0] = FigID.empty;
            jj[4, 4] = FigID.empty;
            jj[4, 5] = FigID.wPawnEnPassantable;

            Boardy.TryMove(new pos(1, 0), new pos(2, 2), FigID.wKnight);
            Boardy.TryRevertLastMove();
            Boardy.TryMove(new pos(1, 0), new pos(2, 2), FigID.wKnight);

            //stopwatch.Stop();
            //Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }
Example #2
0
        protected Lpos BlackPawnMoves()
        {
            var retVal = new Lpos();

            if (AllowExecution())
            {
                switch (position.Item2)
                {
                case 6:         //Starting Position
                    if (state[position.Item1, position.Item2 - 1] == FigID.empty)
                    {
                        retVal.AddRange(PawnWithoutSpecials(Color.white));
                        //Can move 2 fields since at starting position:
                        if (state[position.Item1, position.Item2 - 2] == FigID.empty)
                        {
                            retVal.Add(new pos(position.Item1, (byte)(position.Item2 - 2)));
                        }
                    }
                    break;

                case 3:         //En Passant capture possible
                    retVal.AddRange(PawnWithoutSpecials(Color.white));
                    retVal.AddRange(PawnEnPassantCapture(FigID.wPawnEnPassantable));
                    break;

                case var n when(0 < n && n < ywidth - 2):
                    retVal.AddRange(PawnWithoutSpecials(Color.white));

                    break;
                }
            }
            return(retVal);
        }
Example #3
0
        //----------------------------------
        // Possibly more than one field
        //----------------------------------
        protected Lpos Up()
        {
            var retVal = new Lpos();

            if (AllowExecution())
            {
                for (int i = position.Item2 + 1; i < ywidth; i++)
                {
                    if (state[position.Item1, i] == FigID.empty)
                    {
                        //Empty field, Color = none
                        retVal.Add(new pos(position.Item1, (byte)i));
                        continue;
                    }
                    else if (state.ColorOfField(position.Item1, i) != team)
                    {
                        //Opposite team field
                        retVal.Add(new pos(position.Item1, (byte)i));
                        break;
                    }
                    else
                    {
                        //Same team field
                        break;
                    }
                }
            }
            return(retVal);
        }
Example #4
0
        protected Lpos NorthWest()
        {
            var retVal = new Lpos();

            if (AllowExecution())
            {
                int xPos, yPos;
                for (int i = 1; position.Item1 - i >= 0 && position.Item2 + i < ywidth; i++)
                {
                    xPos = position.Item1 - i;
                    yPos = position.Item2 + i;
                    if (state[xPos, yPos] == FigID.empty)
                    {
                        //Empty field, Color = none
                        retVal.Add(new pos((byte)xPos, (byte)yPos));
                        continue;
                    }
                    else if (state.ColorOfField(xPos, yPos) != team)
                    {
                        //Opposite team field
                        retVal.Add(new pos((byte)xPos, (byte)yPos));
                        break;
                    }
                    else
                    {
                        //Same team field
                        break;
                    }
                }
            }
            return(retVal);
        }
Example #5
0
        protected Lpos Left()
        {
            var retVal = new Lpos();

            if (AllowExecution())
            {
                for (int i = position.Item1 - 1; i >= 0; i--)
                {
                    if (state[i, position.Item2] == FigID.empty)
                    {
                        //Empty field, Color = none
                        retVal.Add(new pos((byte)i, position.Item2));
                        continue;
                    }
                    else if (state.ColorOfField(i, position.Item2) != team)
                    {
                        //Opposite team field
                        retVal.Add(new pos((byte)i, position.Item2));
                        break;
                    }
                    else
                    {
                        //Same team field
                        break;
                    }
                }
            }
            return(retVal);
        }
Example #6
0
        private Lpos PawnEnPassantCapture(FigID oppositeFigID)
        {
            var retVal = new Lpos();

            if (position.Item1 < xwidth - 1 && state[position.Item1 + 1, position.Item2] == oppositeFigID)
            {
                retVal.Add(new pos((byte)(position.Item1 + 1), (byte)(position.Item2 + 1)));
            }
            if (position.Item1 > 0 && state[position.Item1 - 1, position.Item2] == oppositeFigID)
            {
                retVal.Add(new pos((byte)(position.Item1 - 1), (byte)(position.Item2 + 1)));
            }
            return(retVal);
        }
Example #7
0
        private Lpos PawnWithoutSpecials(Color oppositeColor)
        {
            var retVal = new Lpos();

            if (state[position.Item1, position.Item2 + teamSign] == FigID.empty)
            {
                retVal.Add(new pos(position.Item1, (byte)(position.Item2 + teamSign)));
            }
            if (position.Item1 < xwidth - 1 && state.ColorOfField(position.Item1 + 1, position.Item2 + teamSign) == oppositeColor)
            {
                retVal.Add(new pos((byte)(position.Item1 + 1), (byte)(position.Item2 + teamSign)));
            }
            if (position.Item1 > 0 && state.ColorOfField(position.Item1 - 1, position.Item2 + teamSign) == oppositeColor)
            {
                retVal.Add(new pos((byte)(position.Item1 - 1), (byte)(position.Item2 + teamSign)));
            }
            return(retVal);
        }
Example #8
0
        //----------------------------------
        // Special Movement
        //----------------------------------
        protected Lpos KnightJumps()
        {
            var retVal = new Lpos();

            if (AllowExecution())
            {
                int xPos = position.Item1, yPos = position.Item2;
                //Western Hemisphere
                if (xPos - 2 >= 0)
                {
                    if (yPos - 2 >= 0)
                    {
                        //-2,-1
                        //-1,-2
                        if (state.ColorOfField(xPos - 2, yPos - 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 2), (byte)(yPos - 1)));
                        }
                        if (state.ColorOfField(xPos - 1, yPos - 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 1), (byte)(yPos - 2)));
                        }
                    }
                    else if (yPos - 1 >= 0)
                    {
                        //-2,-1
                        if (state.ColorOfField(xPos - 2, yPos - 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 2), (byte)(yPos - 1)));
                        }
                    }

                    if (yPos + 2 < ywidth)
                    {
                        //-2,1
                        //-1,2
                        if (state.ColorOfField(xPos - 2, yPos + 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 2), (byte)(yPos + 1)));
                        }
                        if (state.ColorOfField(xPos - 1, yPos + 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 1), (byte)(yPos + 2)));
                        }
                    }
                    else if (yPos + 1 < ywidth)
                    {
                        //-2,1
                        if (state.ColorOfField(xPos - 2, yPos + 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 2), (byte)(yPos + 1)));
                        }
                    }
                }
                else if (xPos - 1 >= 0)
                {
                    if (yPos - 2 >= 0)
                    {
                        //-1,-2
                        if (state.ColorOfField(xPos - 1, yPos - 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 1), (byte)(yPos - 2)));
                        }
                    }

                    if (yPos + 2 < ywidth)
                    {
                        //-1,2
                        if (state.ColorOfField(xPos - 1, yPos + 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos - 1), (byte)(yPos + 2)));
                        }
                    }
                }

                //Eastern Hemisphere
                if (xPos + 2 < xwidth)
                {
                    if (yPos - 2 >= 0)
                    {
                        //2,-1
                        //1,-2
                        if (state.ColorOfField(xPos + 2, yPos - 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 2), (byte)(yPos - 1)));
                        }
                        if (state.ColorOfField(xPos + 1, yPos - 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 1), (byte)(yPos - 2)));
                        }
                    }
                    else if (yPos - 1 >= 0)
                    {
                        //2,-1
                        if (state.ColorOfField(xPos + 2, yPos - 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 2), (byte)(yPos - 1)));
                        }
                    }

                    if (yPos + 2 < ywidth)
                    {
                        //2,1
                        //1,2
                        if (state.ColorOfField(xPos + 2, yPos + 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 2), (byte)(yPos + 1)));
                        }
                        if (state.ColorOfField(xPos + 1, yPos + 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 1), (byte)(yPos + 2)));
                        }
                    }
                    else if (yPos + 1 < ywidth)
                    {
                        //2,1
                        if (state.ColorOfField(xPos + 2, yPos + 1) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 2), (byte)(yPos + 1)));
                        }
                    }
                }
                else if (xPos + 1 < xwidth)
                {
                    if (yPos - 2 >= 0)
                    {
                        //1,-2
                        if (state.ColorOfField(xPos + 1, yPos - 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 1), (byte)(yPos - 2)));
                        }
                    }

                    if (yPos + 2 < ywidth)
                    {
                        //1,2
                        if (state.ColorOfField(xPos + 1, yPos + 2) != team)
                        {
                            retVal.Add(new pos((byte)(xPos + 1), (byte)(yPos + 2)));
                        }
                    }
                }
            }
            return(retVal);
        }