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); }
//---------------------------------- // 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); }
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); }
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); }
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); }
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); }
//---------------------------------- // 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); }