using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel.Com2Interop;
using System.Xml.Linq;
namespace TheWeirdEngine
{
public struct PosEvaluationResult
{
public bool MeInCheck;
public bool IsStaleMate;
public bool IsMate;
public bool IsDrawByRepetition;
public bool IsDrawBy50Moves;
public bool IsDrawByMaterial;
public sbyte PositionAdvantage;
public int BestMoveidx;
//PositionAdvantageLegenda:
//120 White to move can already take Black's King = illegal
//100 Mate, White wins (also indicated by the separate boolean)
//99 Mate in 1 ply
//98 Mate in 2 plies
//97 Mate in 3 plies (Mate in 2 moves)
//96 Mate in 4 plies
//95 Mate in 5 plies (Mate in 3 moves)
//94 Mate in 6 plies
//93 Mate in 7 plies (Mate in 4 moves)
//92 Mate in 8 plies
//91 Mate in 9 plies (Mate in 5 moves)
//90 - 1 Advantage for White
//0 Draw
//Corresponding negative numbers for Black's perspective
}
public struct Move
{
public byte from_i;
public byte from_j;
public byte to_i;
public byte to_j;
public sbyte PromoteToPiece;
//MyResult will contain the result of evaluation of the position that would result from this move
//MyResult.BestMoveidx is not relevant to fill in here, as it would be the best response to this move
public PosEvaluationResult MyResult;
}
public struct Square
{
public sbyte PieceTypeColour;
//Numbers are hard-coded reserved for pieces
//0 Vacant
//1 King K
//2 Queen Q
//3 Rook R
//4 Knight N
//5 Bishop B
//6 Guard G
//7 Witch W
//8 Pawn p
//Positive number for White piece
//Corresponding negative number for Black piece
public bool EnPassantLeftAllowed;
public bool EnPassantRightAllowed;
//Left-Right is understood from perspective of White player
//Indicates that the pawn, located on this square, is allowed to take en passant from the current position
//Enriched information
public bool ExtraWhiteWitchInfluence;
public bool ExtraBlackWitchInfluence;
//A Witch cannot make an adjacent piece transparent for herself. But an extra friendly Witch could do this.
//So these extra flags are to detect this situation.
public bool WhiteWitchInfluence;
public bool BlackWitchInfluence;
public bool IsAttackedByWhite;
public bool IsAttackedByBlack;
//This can be derived from the primary position information, which is done during enrichment of the position
}
public struct Position
{
public Square [,] MySquare;
//With an 8x8 FIDE chess board:
//(0,0) = a1
//(7,0) = h1
//(0,7) = a8
//(7,7) = h8
public sbyte ColourToMove;//1 White to move -1 Black to move
public byte FiftyMovesRulePlyCount;
//Keeps the number of plies since the last time that a pawn was moved or a piece was taken
public byte RepetitionCount;
//Keeps the total number of times that this position has occurred for threefold repetition rule
//So if value is 3 the position can be evaluated Draw and the engine may claim Draw
public bool CastleWhiteRightBlockedPerm;
public bool CastleWhiteLeftBlockedPerm;
public bool CastleBlackRightBlockedPerm;
public bool CastleBlackLeftBlockedPerm;
//Perm --> Castle permanently not allowed e.g. after Rook or King has moved
//Also here, left/right is understood from Wite's perspective
//Enriched information
public byte WhiteKingLoci;
public byte WhiteKingLocj;
public byte BlackKingLoci;
public byte BlackKingLocj;
public bool CastleWhiteRightBlockedTemp;
public bool CastleWhiteLeftBlockedTemp;
public bool CastleBlackRightBlockedTemp;
public bool CastleBlackLeftBlockedTemp;
//Also here, left/right is understood from Wite's perspective
public bool WhiteIsInCheck;
public bool BlackIsInCheck;
public Move[] MovesFromHere;
public int NumberOfFoundMoves;
//Temp --> Castle temporarily not allowed because of the current position
//This can be derived from the primary position information, which is done during enrichment of the position
}
public struct Game
{
public int NumberOfFiles;//Determins the width of the board
public int NumberOfRanks;
//e.g. for the standard 10x8 Bulldog chess board NumberOfFiles = 10, NumberOfRanks = 8
public int CastleDistance;
//The number of squares that a King is displaced with castling
public int NumberOfPositionsInGame;
public int ActualCurrentPositionidx;
public Position[] MyPosition;
//A game contains all past positions from the start till the current position of the game
//Even when you want to consider one position, it will be stored as a Game containing only your position
//Position[0] is the starting position
//The calculation procedures will do and undo moves and by doing so alter NumberOfPositionsInGame
//MyPosition[NumberOfPositionsInGame - 1] is supposed to be the current position, also within a hypothetical
//calculation line
//ActualCurrentPositionidx is supposed to indicate the current position without additional calculation lines
//MyPosition[ActualCurrentPositionidx] is supposed to be the current position, NOT taking into account
//hypothetical calculation lines
public string CalculationLineMessage;
}
public class WeirdEngineBackend
{
public const int MaxNumberOfPositions = 1000;
//FindOnly1stMate_n_line tells the Engine to stop evaluating more moves from the current position and calculation context
//once one mating move has been found
public bool FindOnly1stMate_n_line;
public int NumberOfPliesToCalculate;
public Game MyGame;
public WeirdEngineBackend(int pNumberOfFiles, int pNumberOfRanks)
{
this.MyGame = new Game();
this.FindOnly1stMate_n_line = true;//Can be overruled from settings file
this.NumberOfPliesToCalculate = 3;//Can be overruled from settings file
this.ResetGame(pNumberOfFiles, pNumberOfRanks, 1);
}
private void ResetGame(int pNumberOfFiles, int pNumberOfRanks, int pNumberOfPositionsInGame)
{
int i;
this.MyGame.MyPosition = null;
this.MyGame.NumberOfFiles = pNumberOfFiles;
this.MyGame.NumberOfRanks = pNumberOfRanks;
this.MyGame.NumberOfPositionsInGame = pNumberOfPositionsInGame;
this.MyGame.ActualCurrentPositionidx = pNumberOfPositionsInGame - 1;
this.MyGame.MyPosition = new Position[MaxNumberOfPositions];
for (i = 0; i < MaxNumberOfPositions; i++)
{
this.MyGame.MyPosition[i].MySquare = new Square[this.MyGame.NumberOfFiles, this.MyGame.NumberOfRanks];
this.MyGame.MyPosition[i].MovesFromHere = new Move[10000];
this.MyGame.MyPosition[i].CastleWhiteLeftBlockedPerm = false;
this.MyGame.MyPosition[i].CastleWhiteRightBlockedPerm = false;
this.MyGame.MyPosition[i].CastleBlackLeftBlockedPerm = false;
this.MyGame.MyPosition[i].CastleBlackRightBlockedPerm = false;
}
}
private bool IsDrawByInsufficientMaterial(int pPositionNumber)
{
int i;
int j;
int WhiteBishopCountOnWhite;
int WhiteBishopCountOnBlack;
int WhiteKnightCount;
int BlackBishopCountOnWhite;
int BlackBishopCountOnBlack;
int BlackKnightCount;
WhiteBishopCountOnWhite = 0;
WhiteBishopCountOnBlack = 0;
WhiteKnightCount = 0;
BlackBishopCountOnWhite = 0;
BlackBishopCountOnBlack = 0;
BlackKnightCount = 0;
for (i = 0; i < this.MyGame.NumberOfFiles; i++)
{
for (j = 0; j < MyGame.NumberOfRanks; j++)
{
//4 Knight N
//5 Bishop B
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 2 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == -2 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 3 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == -3 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 6 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == -6 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 8 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == -8)
{
return false;
}
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 4)
{
WhiteKnightCount++;
}
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 5)
{
if ((i + j) % 2 == 0)
{
WhiteBishopCountOnWhite++;
} else
{
WhiteBishopCountOnBlack++;
}
}
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == -4)
{
BlackKnightCount++;
}
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == -5)
{
if ((i + j) % 2 == 0)
{
BlackBishopCountOnWhite++;
}
else
{
BlackBishopCountOnBlack++;
}
}
}
}
if (WhiteBishopCountOnWhite > 0 & WhiteKnightCount > 0)
{
return false;
}
if (WhiteBishopCountOnBlack > 0 & WhiteKnightCount > 0)
{
return false;
}
if (WhiteBishopCountOnWhite > 0 & WhiteBishopCountOnBlack > 0)
{
return false;
}
if (BlackBishopCountOnWhite > 0 & BlackKnightCount > 0)
{
return false;
}
if (BlackBishopCountOnBlack > 0 & BlackKnightCount > 0)
{
return false;
}
if (BlackBishopCountOnWhite > 0 & BlackBishopCountOnBlack > 0)
{
return false;
}
if (WhiteKnightCount > 2 | BlackKnightCount > 2)
{
return false;
}
return true;
}
//EvaluationByCalculation and EvaluationByPosition have a lot of code in common
//But are also each doing really different things
private PosEvaluationResult EvaluationByCalculation(int pPositionNumber, int pNumberOfPlies)
{
PosEvaluationResult output;
int mn;
bool LegalMoveFound;
bool MatingMoveFound;
sbyte BestFoundAdvantage;
sbyte RelativeBestFoundAdvantage;
string prevCalculationLineMessage;
int NumberOfPliesFromHere;
output.MeInCheck = false;
output.IsStaleMate = false;
output.IsMate = false;
output.IsDrawByRepetition = false;
output.IsDrawBy50Moves = false;
output.IsDrawByMaterial = false;
output.PositionAdvantage = 0;
output.BestMoveidx = 0;
//When already at deepest calculation level, evaluate the position only
if (pNumberOfPlies == 0)
{
output = this.EvaluationByPosition(pPositionNumber);
return output;
}
NumberOfPliesFromHere = pNumberOfPlies;
//Enrich this position
this.ListMovesAndEnrich(pPositionNumber, 0);
//Detect an illegal position where own King is in check
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].BlackIsInCheck)
{
output.MeInCheck = true;
output.PositionAdvantage = 120;
return output;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].WhiteIsInCheck)
{
output.MeInCheck = true;
output.PositionAdvantage = -120;
return output;
}
LegalMoveFound = false;
BestFoundAdvantage = (sbyte)(this.MyGame.MyPosition[pPositionNumber].ColourToMove * -120);
MatingMoveFound = false;
mn = 0;
while (mn < this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves & MatingMoveFound == false)
{
prevCalculationLineMessage = this.MyGame.CalculationLineMessage;
this.MyGame.CalculationLineMessage = this.MyGame.CalculationLineMessage + "|" +
this.MoveAsString(this.MyGame.MyPosition[pPositionNumber], mn);
Application.DoEvents();
//Build the positions resulting from each of the moves
this.DoMove(pPositionNumber, mn);
//Recursive call to the same procedure
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[mn].MyResult =
this.EvaluationByCalculation(pPositionNumber + 1, NumberOfPliesFromHere - 1);
//This also enriches this position resulting from this move
this.MyGame.CalculationLineMessage = prevCalculationLineMessage;
//Detect mate or stalemate
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber + 1].WhiteIsInCheck == false)
{
LegalMoveFound = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber + 1].BlackIsInCheck == false)
{
LegalMoveFound = true;
}
this.UndoLastMove(pPositionNumber + 1);
//Keep track of best so far
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MovesFromHere[mn].MyResult.PositionAdvantage > BestFoundAdvantage)
{
output.BestMoveidx = mn;
BestFoundAdvantage = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[mn].MyResult.PositionAdvantage;
}
} else
{
if (this.MyGame.MyPosition[pPositionNumber].MovesFromHere[mn].MyResult.PositionAdvantage < BestFoundAdvantage)
{
output.BestMoveidx = mn;
BestFoundAdvantage = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[mn].MyResult.PositionAdvantage;
}
}
//Now reduce the search depth when a forced mate has already been found
RelativeBestFoundAdvantage = (sbyte)(BestFoundAdvantage * this.MyGame.MyPosition[pPositionNumber].ColourToMove);
if (FindOnly1stMate_n_line == true)
{
switch (RelativeBestFoundAdvantage)
{
case 100:
MatingMoveFound = true;
break;
case 98:
NumberOfPliesFromHere = 1;
break;
case 96:
NumberOfPliesFromHere = 3;
break;
case 94:
NumberOfPliesFromHere = 5;
break;
case 92:
NumberOfPliesFromHere = 7;
break;
}
}
mn++;
}
//Detect mate or stalemate
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 & LegalMoveFound == false)
{
if (this.MyGame.MyPosition[pPositionNumber].WhiteIsInCheck == true)
{
//White is mated
output.IsMate = true;
output.PositionAdvantage = -100;
return output;
}
else
{
//White is stalemated
output.IsStaleMate = true;
output.PositionAdvantage = 0;
return output;
}
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 & LegalMoveFound == false)
{
if (this.MyGame.MyPosition[pPositionNumber].BlackIsInCheck == true)
{
//Black is mated
output.IsMate = true;
output.PositionAdvantage = 100;
return output;
}
else
{
//Black is stalemated
output.IsStaleMate = true;
output.PositionAdvantage = 0;
return output;
}
}
//Detect draw by repetition/50 moves
if (this.MyGame.MyPosition[pPositionNumber].RepetitionCount >= 3)
{
output.IsDrawByRepetition = true;
output.PositionAdvantage = 0;
return output;
}
if (this.MyGame.MyPosition[pPositionNumber].FiftyMovesRulePlyCount >= 100)
{
output.IsDrawBy50Moves = true;
output.PositionAdvantage = 0;
return output;
}
if (this.IsDrawByInsufficientMaterial(pPositionNumber))
{
output.IsDrawByMaterial = true;
output.PositionAdvantage = 0;
return output;
}
mn = output.BestMoveidx;
output.PositionAdvantage = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[mn].MyResult.PositionAdvantage;
if (output.PositionAdvantage > 90)
{
output.PositionAdvantage--;
}
if (output.PositionAdvantage < -90)
{
output.PositionAdvantage++;
}
return output;
}
private PosEvaluationResult EvaluationByMaterial(int pPositionNumber)
{
PosEvaluationResult output;
int i;
int j;
int NetMaterialValue;
NetMaterialValue = 0;
for (i = 0; i < this.MyGame.NumberOfFiles; i++)
{
for (j = 0; j < this.MyGame.NumberOfRanks; j++)
{
switch (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour)
{
case 2: NetMaterialValue = NetMaterialValue + 9; break;
case -2: NetMaterialValue = NetMaterialValue - 9; break;
case 3: NetMaterialValue = NetMaterialValue + 5; break;
case -3: NetMaterialValue = NetMaterialValue - 5; break;
case 4: NetMaterialValue = NetMaterialValue + 3; break;
case -4: NetMaterialValue = NetMaterialValue - 3; break;
case 5: NetMaterialValue = NetMaterialValue + 3; break;
case -5: NetMaterialValue = NetMaterialValue - 3; break;
case 6: NetMaterialValue = NetMaterialValue + 4; break;
case -6: NetMaterialValue = NetMaterialValue - 4; break;
case 7: NetMaterialValue = NetMaterialValue + 3; break;
case -7: NetMaterialValue = NetMaterialValue - 3; break;
case 8: NetMaterialValue = NetMaterialValue + 1; break;
case -8: NetMaterialValue = NetMaterialValue - 1; break;
}
}
}
output.MeInCheck = false;
output.IsStaleMate = false;
output.IsMate = false;
output.IsDrawByRepetition = false;
output.IsDrawBy50Moves = false;
output.IsDrawByMaterial = false;
output.PositionAdvantage = 0;
output.BestMoveidx = 0;
if (NetMaterialValue > 9)
{
output.PositionAdvantage = 70;
return output;
}
if (NetMaterialValue > 5)
{
output.PositionAdvantage = 50;
return output;
}
if (NetMaterialValue > 2)
{
output.PositionAdvantage = 20;
return output;
}
if (NetMaterialValue < -9)
{
output.PositionAdvantage =-70;
return output;
}
if (NetMaterialValue < -5)
{
output.PositionAdvantage = -50;
return output;
}
if (NetMaterialValue < -2)
{
output.PositionAdvantage = -20;
return output;
}
output.PositionAdvantage = (sbyte)((NetMaterialValue * 2) + this.MyGame.MyPosition[pPositionNumber].ColourToMove);
return output;
}
private PosEvaluationResult EvaluationByPosition(int pPositionNumber)
{
PosEvaluationResult output;
PosEvaluationResult material;
int mn;
bool LegalMoveFound;
output.MeInCheck = false;
output.IsStaleMate = false;
output.IsMate = false;
output.IsDrawByRepetition = false;
output.IsDrawBy50Moves = false;
output.IsDrawByMaterial = false;
output.PositionAdvantage = 0;
output.BestMoveidx = 0;
//Enrich this position
this.ListMovesAndEnrich(pPositionNumber, 0);
//Detect an illegal position where own King is in check
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].BlackIsInCheck)
{
output.MeInCheck = true;
output.PositionAdvantage = 120;
return output;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].WhiteIsInCheck)
{
output.MeInCheck = true;
output.PositionAdvantage = -120;
return output;
}
LegalMoveFound = false;
mn = 0;
while (mn < this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves & LegalMoveFound == false)
{
//Build the positions resulting from each of the moves
this.DoMove(pPositionNumber, mn);
//Enrich the position resulting from the moves
this.ListMovesAndEnrich(pPositionNumber + 1, 1);
//Detect mate or stalemate
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber + 1].WhiteIsInCheck == false)
{
LegalMoveFound = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber + 1].BlackIsInCheck == false)
{
LegalMoveFound = true;
}
this.UndoLastMove(pPositionNumber + 1);
mn++;
}
//Detect mate or stalemate
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 & LegalMoveFound == false)
{
if (this.MyGame.MyPosition[pPositionNumber].WhiteIsInCheck == true)
{
//White is mated
output.IsMate = true;
output.PositionAdvantage = -100;
return output;
} else
{
//White is stalemated
output.IsStaleMate = true;
output.PositionAdvantage = 0;
return output;
}
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 & LegalMoveFound == false)
{
if (this.MyGame.MyPosition[pPositionNumber].BlackIsInCheck == true)
{
//Black is mated
output.IsMate = true;
output.PositionAdvantage = 100;
return output;
}
else
{
//Black is stalemated
output.IsStaleMate = true;
output.PositionAdvantage = 0;
return output;
}
}
//Detect draw by repetition/50 moves
if (this.MyGame.MyPosition[pPositionNumber].RepetitionCount >= 3)
{
output.IsDrawByRepetition = true;
output.PositionAdvantage = 0;
return output;
}
if (this.MyGame.MyPosition[pPositionNumber].FiftyMovesRulePlyCount >= 100)
{
output.IsDrawBy50Moves = true;
output.PositionAdvantage = 0;
return output;
}
if (this.IsDrawByInsufficientMaterial(pPositionNumber))
{
output.IsDrawByMaterial = true;
output.PositionAdvantage = 0;
return output;
}
//From here, material advantage and positional advantage should be calculated, and it is Work in Progress
//This should lead to a resulting number between 90 and 1 (depending for the advantage for White)
// or between -1 and -90 (depending on the advantage for Black)
material = this.EvaluationByMaterial(pPositionNumber);
output.PositionAdvantage = material.PositionAdvantage;
return output;
}
public void SuggestMove()
{
PosEvaluationResult MyStaticEvaluation;
int p;
string s;
p = this.MyGame.NumberOfPositionsInGame - 1;
this.MyGame.CalculationLineMessage = "";
MyStaticEvaluation = EvaluationByCalculation(p, this.NumberOfPliesToCalculate);
s = this.MoveAsString(this.MyGame.MyPosition[p], MyStaticEvaluation.BestMoveidx)
+ "|" + PosEvaluationResultAsString(MyStaticEvaluation);
MessageBox.Show(s);
}
//Here the section starts that makes a move effective in the next position
private void UndoLastMove(int pFromPositionNumber)
{
//int i;
//int j;
//I presume that we could skip this for-loop, information is always completely overwritten
//for (i = 0; i < this.MyGame.NumberOfFiles; i++)
//{
// for (j = 0; j < this.MyGame.NumberOfRanks; j++)
// {
// this.MyGame.MyPosition[pFromPositionNumber].MySquare[i, j].PieceTypeColour = 0;
// this.MyGame.MyPosition[pFromPositionNumber].MySquare[i, j].EnPassantLeftAllowed = false;
// this.MyGame.MyPosition[pFromPositionNumber].MySquare[i, j].EnPassantRightAllowed = false;
// }
//}
this.MyGame.MyPosition[pFromPositionNumber].ColourToMove = 0;
this.MyGame.MyPosition[pFromPositionNumber].CastleWhiteRightBlockedPerm = false;
this.MyGame.MyPosition[pFromPositionNumber].CastleWhiteLeftBlockedPerm = false;
this.MyGame.MyPosition[pFromPositionNumber].CastleBlackRightBlockedPerm = false;
this.MyGame.MyPosition[pFromPositionNumber].CastleBlackLeftBlockedPerm = false;
this.MyGame.MyPosition[pFromPositionNumber].RepetitionCount = 0;
this.MyGame.MyPosition[pFromPositionNumber].FiftyMovesRulePlyCount = 0;
this.MyGame.NumberOfPositionsInGame--;
}
private void DoMove(int pFromPositionNumber, int pMoveidx)
{
byte from_i;
byte from_j;
byte to_i;
byte to_j;
bool MoveDone;
int p;
bool MatchFound;
MoveDone = false;
//First we copy the content of the current position to the next entry of array MyPosition
//This initializes the e.p. flags and already switches the ColourToMove
this.CopyPositionFrom(pFromPositionNumber);
//Increase NumberOfPositionsInGame
this.MyGame.NumberOfPositionsInGame++;
from_i = this.MyGame.MyPosition[pFromPositionNumber].MovesFromHere[pMoveidx].from_i;
from_j = this.MyGame.MyPosition[pFromPositionNumber].MovesFromHere[pMoveidx].from_j;
to_i = this.MyGame.MyPosition[pFromPositionNumber].MovesFromHere[pMoveidx].to_i;
to_j = this.MyGame.MyPosition[pFromPositionNumber].MovesFromHere[pMoveidx].to_j;
//Now set the e.p. flags in the new position
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 8 |
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -8)
{
if (Math.Abs(from_j - to_j) == 2)
{
if (to_i < this.MyGame.NumberOfFiles - 1)
{
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour *
this.MyGame.MyPosition[pFromPositionNumber].MySquare[to_i + 1, to_j].PieceTypeColour == -64)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].MySquare[to_i + 1, to_j].EnPassantLeftAllowed = true;
}
}
if (to_i > 0)
{
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour *
this.MyGame.MyPosition[pFromPositionNumber].MySquare[to_i - 1, to_j].PieceTypeColour == -64)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].MySquare[to_i - 1, to_j].EnPassantRightAllowed = true;
}
}
}
}
//Do the en passant capture
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].EnPassantLeftAllowed == true &
to_i == from_i - 1 & MoveDone == false)
{
this.DoMoveEnPassant(pFromPositionNumber + 1, from_i, from_j, to_i, to_j);
MoveDone = true;
}
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].EnPassantRightAllowed == true &
to_i == from_i + 1 & MoveDone == false)
{
this.DoMoveEnPassant(pFromPositionNumber + 1, from_i, from_j, to_i, to_j);
MoveDone = true;
}
//Do the castling
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 1 |
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -1)
{
if (Math.Abs(from_i - to_i) == this.MyGame.CastleDistance & MoveDone == false)
{
this.DoMoveCastle(pFromPositionNumber + 1, from_i, from_j, to_i, to_j);
MoveDone = true;
}
}
//Do the other moves
if (MoveDone == false)
{
this.DoMoveGeneric(pFromPositionNumber + 1, from_i, from_j, to_i, to_j);
MoveDone = true;
}
//(Overwriting the PieceTypeColour implicitly removes the captured piece)
//Promote a pawn moving to the last rank
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 8 &
to_j == this.MyGame.NumberOfRanks - 1)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].MySquare[to_i, to_j].PieceTypeColour =
this.MyGame.MyPosition[pFromPositionNumber].MovesFromHere[pMoveidx].PromoteToPiece;
}
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -8 &
to_j == 0)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].MySquare[to_i, to_j].PieceTypeColour =
this.MyGame.MyPosition[pFromPositionNumber].MovesFromHere[pMoveidx].PromoteToPiece;
}
//Detect that castle is no longer allowed after a Rook move or King move
if (from_i == 0 & from_j == 0 &
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 3)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleWhiteLeftBlockedPerm = true;
}
if (from_i == this.MyGame.NumberOfFiles - 1 & from_j == 0 &
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 3)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleWhiteRightBlockedPerm = true;
}
if (from_i == 0 & from_j == this.MyGame.NumberOfRanks - 1 &
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -3)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleBlackLeftBlockedPerm = true;
}
if (from_i == this.MyGame.NumberOfFiles - 1 & from_j == this.MyGame.NumberOfRanks - 1 &
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -3)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleBlackRightBlockedPerm = true;
}
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 1)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleWhiteLeftBlockedPerm = true;
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleWhiteRightBlockedPerm = true;
}
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -1)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleBlackLeftBlockedPerm = true;
this.MyGame.MyPosition[pFromPositionNumber + 1].CastleBlackRightBlockedPerm = true;
}
//Update the 50 moves rule ply counter
if (this.MyGame.MyPosition[pFromPositionNumber].MySquare[to_i, to_j].PieceTypeColour != 0 |
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == 8 |
this.MyGame.MyPosition[pFromPositionNumber].MySquare[from_i, from_j].PieceTypeColour == -8)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].FiftyMovesRulePlyCount = 0;
} else
{
this.MyGame.MyPosition[pFromPositionNumber + 1].FiftyMovesRulePlyCount =
(byte)(this.MyGame.MyPosition[pFromPositionNumber].FiftyMovesRulePlyCount + 1);
}
//Update the 3-fold repetition counter
MatchFound = false;
p = pFromPositionNumber;
while (p > 0 & MatchFound == false)
{
p--;
if (PositionsEqual(pFromPositionNumber + 1, p) == true)
{
MatchFound = true;
}
}
if (MatchFound == true)
{
this.MyGame.MyPosition[pFromPositionNumber + 1].RepetitionCount =
(byte)(this.MyGame.MyPosition[p].RepetitionCount + 1);
}
else
{
this.MyGame.MyPosition[pFromPositionNumber + 1].RepetitionCount = 1;
}
}
private void CopyPositionFrom(int pFromPositionNumber)
{
int i;
int j;
int p;
int q;
p = pFromPositionNumber;
q = p + 1;
for (i = 0; i < this.MyGame.NumberOfFiles; i++)
{
for (j = 0; j < this.MyGame.NumberOfRanks; j++)
{
this.MyGame.MyPosition[q].MySquare[i, j].PieceTypeColour = this.MyGame.MyPosition[p].MySquare[i, j].PieceTypeColour;
this.MyGame.MyPosition[q].MySquare[i, j].EnPassantLeftAllowed = false;
this.MyGame.MyPosition[q].MySquare[i, j].EnPassantRightAllowed = false;
}
}
this.MyGame.MyPosition[q].ColourToMove = (sbyte)((-1) * this.MyGame.MyPosition[p].ColourToMove);
this.MyGame.MyPosition[q].CastleWhiteRightBlockedPerm = this.MyGame.MyPosition[p].CastleWhiteRightBlockedPerm;
this.MyGame.MyPosition[q].CastleWhiteLeftBlockedPerm = this.MyGame.MyPosition[p].CastleWhiteLeftBlockedPerm;
this.MyGame.MyPosition[q].CastleBlackRightBlockedPerm = this.MyGame.MyPosition[p].CastleBlackRightBlockedPerm;
this.MyGame.MyPosition[q].CastleBlackLeftBlockedPerm = this.MyGame.MyPosition[p].CastleBlackLeftBlockedPerm;
}
private bool PositionsEqual(int p1, int p2)
{
//To compare two positions as to decide for draw by 3-fold repetition
byte i;
byte j;
if (this.MyGame.MyPosition[p1].ColourToMove != this.MyGame.MyPosition[p2].ColourToMove)
{
return false;
}
if (this.MyGame.MyPosition[p1].CastleWhiteRightBlockedPerm != this.MyGame.MyPosition[p2].CastleWhiteRightBlockedPerm)
{
return false;
}
if (this.MyGame.MyPosition[p1].CastleWhiteLeftBlockedPerm != this.MyGame.MyPosition[p2].CastleWhiteLeftBlockedPerm)
{
return false;
}
if (this.MyGame.MyPosition[p1].CastleBlackRightBlockedPerm != this.MyGame.MyPosition[p2].CastleBlackRightBlockedPerm)
{
return false;
}
if (this.MyGame.MyPosition[p1].CastleBlackLeftBlockedPerm != this.MyGame.MyPosition[p2].CastleBlackLeftBlockedPerm)
{
return false;
}
for (i = 0; i < this.MyGame.NumberOfFiles; i++)
{
for (j = 0; j < this.MyGame.NumberOfRanks; j++)
{
if (this.MyGame.MyPosition[p1].MySquare[i, j].PieceTypeColour !=
this.MyGame.MyPosition[p2].MySquare[i, j].PieceTypeColour)
{
return false;
}
if (this.MyGame.MyPosition[p1].MySquare[i, j].EnPassantLeftAllowed !=
this.MyGame.MyPosition[p2].MySquare[i, j].EnPassantLeftAllowed)
{
return false;
}
if (this.MyGame.MyPosition[p1].MySquare[i, j].EnPassantRightAllowed !=
this.MyGame.MyPosition[p2].MySquare[i, j].EnPassantRightAllowed)
{
return false;
}
}
}
return true;
}
private void DoMoveEnPassant(int pPositionNumber, byte pfrom_i, byte pfrom_j, byte pto_i, byte pto_j)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pto_i, pto_j].PieceTypeColour =
this.MyGame.MyPosition[pPositionNumber].MySquare[pfrom_i, pfrom_j].PieceTypeColour;
this.MyGame.MyPosition[pPositionNumber].MySquare[pfrom_i, pfrom_j].PieceTypeColour = 0;
this.MyGame.MyPosition[pPositionNumber].MySquare[pto_i, pfrom_j].PieceTypeColour = 0;
}
private void DoMoveCastle(int pPositionNumber, byte pfrom_i, byte pfrom_j, byte pto_i, byte pto_j)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pto_i, pto_j].PieceTypeColour =
this.MyGame.MyPosition[pPositionNumber].MySquare[pfrom_i, pfrom_j].PieceTypeColour;
this.MyGame.MyPosition[pPositionNumber].MySquare[pfrom_i, pfrom_j].PieceTypeColour = 0;
if (pto_i < pfrom_i)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pto_i + 1, pto_j].PieceTypeColour =
this.MyGame.MyPosition[pPositionNumber].MySquare[0, pfrom_j].PieceTypeColour;
this.MyGame.MyPosition[pPositionNumber].MySquare[0, pfrom_j].PieceTypeColour = 0;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pto_i - 1, pto_j].PieceTypeColour =
this.MyGame.MyPosition[pPositionNumber].MySquare[this.MyGame.NumberOfFiles - 1, pfrom_j].PieceTypeColour;
this.MyGame.MyPosition[pPositionNumber].MySquare[MyGame.NumberOfFiles - 1, pfrom_j].PieceTypeColour = 0;
}
}
private void DoMoveGeneric(int pPositionNumber, byte pfrom_i, byte pfrom_j, byte pto_i, byte pto_j)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pto_i, pto_j].PieceTypeColour =
this.MyGame.MyPosition[pPositionNumber].MySquare[pfrom_i, pfrom_j].PieceTypeColour;
this.MyGame.MyPosition[pPositionNumber].MySquare[pfrom_i, pfrom_j].PieceTypeColour = 0;
}
//Here the section ENDS that makes a move effective in the next position
//Here the section starts that generates a list of moves from a given position
private void Init_Move_Evaluation_Results(int pPositionNumber)
{
int nm;
for (nm = 0; nm < this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves; nm++)
{
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.MeInCheck = false;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.IsStaleMate = false;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.IsMate = false;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.IsDrawByRepetition = false;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.IsDrawBy50Moves = false;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.IsDrawByMaterial = false;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.PositionAdvantage = 0;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].MyResult.BestMoveidx = -1;
}
}
private void ListMovesAndEnrich(int pPositionNumber, int pPurpose)
{
//pPurpose: 0 = full, 1 = scan if opponent is in check, 2 = scan opponent's attacks
byte i1;
byte j1;
if (pPurpose == 0 | pPurpose == 1)
{
this.Enrich_Initialize(pPositionNumber);
this.EnrichWitchInfluence(pPositionNumber);
}
//We want to mark the squares attacked by the opponent by looking at all possible opponent's moves:
if (pPurpose == 0)
{
this.ListMovesAndEnrich(pPositionNumber, 2);
}
//This has been added in MovesFromHere, but now resetting the counter to overwrite it
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves = 0;
//The content of the array MovesFromHere is not erased because no fast method exists for this.
//The initialize method does not accomplish this
//So possibly, beyond NumberOfFoundMoves - 1, values are still in place from previous calls to ListMoves
if (pPurpose == 2)
{
//swap ColourToMove
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1)
{
this.MyGame.MyPosition[pPositionNumber].ColourToMove = 1;
}
else
{
this.MyGame.MyPosition[pPositionNumber].ColourToMove = -1;
}
}
for (i1 = 0; i1 < this.MyGame.NumberOfFiles; i1++)
{
for (j1 = 0; j1 < this.MyGame.NumberOfRanks; j1++)
{
switch (this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].PieceTypeColour)
{
case 1:
this.MyGame.MyPosition[pPositionNumber].WhiteKingLoci = i1;
this.MyGame.MyPosition[pPositionNumber].WhiteKingLocj = j1;
break;
case -1:
this.MyGame.MyPosition[pPositionNumber].BlackKingLoci = i1;
this.MyGame.MyPosition[pPositionNumber].BlackKingLocj = j1;
break;
}
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove > 0)
{
switch (this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].PieceTypeColour)
{
case 1: this.ListMoves_Guard(i1, j1, pPositionNumber); break;
case -1: this.ListMoves_Guard(i1, j1, pPositionNumber); break;
case 6: this.ListMoves_Guard(i1, j1, pPositionNumber); break;
case -6: this.ListMoves_Guard(i1, j1, pPositionNumber); break;
case 4: this.ListMoves_Knight(i1, j1, pPositionNumber); break;
case -4: this.ListMoves_Knight(i1, j1, pPositionNumber); break;
case 8: this.ListMoves_White_Pawn(i1, j1, pPositionNumber); break;
case -8: this.ListMoves_Black_Pawn(i1, j1, pPositionNumber); break;
case 3: this.ListMoves_Rook(i1, j1, pPositionNumber); break;
case -3: this.ListMoves_Rook(i1, j1, pPositionNumber); break;
case 5: this.ListMoves_Bishop(i1, j1, pPositionNumber); break;
case -5: this.ListMoves_Bishop(i1, j1, pPositionNumber); break;
case 7:
if (pPurpose == 0)
{
this.ListMoves_Witch(i1, j1, pPositionNumber);
}
break;
case -7:
if (pPurpose == 0)
{
this.ListMoves_Witch(i1, j1, pPositionNumber);
}
break;
case 2:
this.ListMoves_Rook(i1, j1, pPositionNumber);
this.ListMoves_Bishop(i1, j1, pPositionNumber);
break;
case -2:
this.ListMoves_Rook(i1, j1, pPositionNumber);
this.ListMoves_Bishop(i1, j1, pPositionNumber);
break;
}
}
}
}
if (pPurpose == 2)
{
//UNDO swap ColourToMove
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1)
{
this.MyGame.MyPosition[pPositionNumber].ColourToMove = 1;
}
else
{
this.MyGame.MyPosition[pPositionNumber].ColourToMove = -1;
}
}
if (pPurpose == 0 | pPurpose == 1)
{
this.Enrich_IsInCheck(pPositionNumber);
}
if (pPurpose == 0)
{
this.Enrich_CastleWhiteLeftBlockedTemp(pPositionNumber);
this.Enrich_CastleWhiteRightBlockedTemp(pPositionNumber);
this.Enrich_CastleBlackLeftBlockedTemp(pPositionNumber);
this.Enrich_CastleBlackRightBlockedTemp(pPositionNumber);
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove > 0)
{
i1 = this.MyGame.MyPosition[pPositionNumber].WhiteKingLoci;
j1 = this.MyGame.MyPosition[pPositionNumber].WhiteKingLocj;
this.ListMoves_King(i1, j1, pPositionNumber);
}
else
{
i1 = this.MyGame.MyPosition[pPositionNumber].BlackKingLoci;
j1 = this.MyGame.MyPosition[pPositionNumber].BlackKingLocj;
this.ListMoves_King(i1, j1, pPositionNumber);
}
//Result of evaluation of moves must explicitly be initialized, as it is only optionally updated
this.Init_Move_Evaluation_Results(pPositionNumber);
}
}
private void ListMoves_Guard(byte pi, byte pj, int pPositionNumber)
{
int i2;
int j2;
int nm;
for (i2 = Math.Max(0, pi - 1); i2 < Math.Min(this.MyGame.NumberOfFiles, pi + 2); i2++)
{
for (j2 = Math.Max(0, pj - 1); j2 < Math.Min(this.MyGame.NumberOfRanks, pj + 2); j2++)
{
if (i2 != pi | j2 != pj)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].IsAttackedByBlack = true; }
if (MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i2;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j2;
}
}
}
}
}
private void ListMoves_King(int pi, int pj, int pPositionNumber)
{
int nm;
//Normal king moves have already been listed by procedure ListMoves_Guard
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 1)
{
if (this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedPerm == false &
this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedTemp == false)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - this.MyGame.CastleDistance);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)pj;
}
if (this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedPerm == false &
this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedTemp == false)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + this.MyGame.CastleDistance);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)pj;
}
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedPerm == false &
this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedTemp == false)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - this.MyGame.CastleDistance);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)pj;
}
if (this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedPerm == false &
this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedTemp == false)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + this.MyGame.CastleDistance);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)pj;
}
}
}
private void ListMoves_Knight(int pi, int pj, int pPositionNumber)
{
int nm;
if (pi > 0 & pj > 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj - 2].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj - 2].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj - 2].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 2);
}
}
if (pi > 0 & pj < MyGame.NumberOfRanks - 2)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj + 2].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj + 2].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj + 2].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 2);
}
}
if (pi < this.MyGame.NumberOfFiles - 1 & pj > 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj - 2].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj - 2].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj - 2].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 2);
}
}
if (pi < this.MyGame.NumberOfFiles - 1 & pj < MyGame.NumberOfRanks - 2)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj + 2].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj + 2].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj + 2].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 2);
}
}
if (pi > 1 & pj > 0)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj - 1].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj - 1].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj - 1].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
}
}
if (pi > 1 & pj < MyGame.NumberOfRanks - 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj + 1].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj + 1].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj + 1].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
}
}
if (pi < this.MyGame.NumberOfFiles - 2 & pj > 0)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj - 1].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj - 1].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj - 1].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
}
}
if (pi < this.MyGame.NumberOfFiles - 2 & pj < MyGame.NumberOfRanks - 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour > 0)
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj + 1].IsAttackedByWhite = true; }
else
{ this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj + 1].IsAttackedByBlack = true; }
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj + 1].PieceTypeColour <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
}
}
}
private void ListMoves_White_Pawn(int pi, int pj, int pPositionNumber)
{
int nm;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj + 1].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
this.Promote_White_Pawn(pPositionNumber);
}
if (pj == 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj + 2].PieceTypeColour == 0 &
(this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj + 1].PieceTypeColour == 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj + 1].WhiteWitchInfluence == true))
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 2);
}
}
if (pi > 0)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj + 1].IsAttackedByWhite = true;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj + 1].PieceTypeColour < 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].EnPassantLeftAllowed == true)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
this.Promote_White_Pawn(pPositionNumber);
}
}
if (pi < this.MyGame.NumberOfFiles - 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj + 1].IsAttackedByWhite = true;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj + 1].PieceTypeColour < 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].EnPassantRightAllowed == true)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
this.Promote_White_Pawn(pPositionNumber);
}
}
}
private void Promote_White_Pawn(int pPositionNumber)
{
int nm;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
if (this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j == this.MyGame.NumberOfRanks - 1)
{
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = 2;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = 3;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = 4;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = 5;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = 6;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = 7;
}
}
private void ListMoves_Black_Pawn(int pi, int pj, int pPositionNumber)
{
int nm;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj - 1].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
this.Promote_Black_Pawn(pPositionNumber);
}
if (pj == this.MyGame.NumberOfRanks - 2)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj - 2].PieceTypeColour == 0 &
(this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj - 1].PieceTypeColour == 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj - 1].BlackWitchInfluence == true))
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 2);
}
}
if (pi > 0)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj - 1].IsAttackedByBlack = true;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj - 1].PieceTypeColour > 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].EnPassantLeftAllowed == true)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
this.Promote_Black_Pawn(pPositionNumber);
}
}
if (pi < this.MyGame.NumberOfFiles - 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj - 1].IsAttackedByBlack = true;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj - 1].PieceTypeColour > 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].EnPassantRightAllowed == true)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
this.Promote_Black_Pawn(pPositionNumber);
}
}
}
private void Promote_Black_Pawn(int pPositionNumber)
{
int nm;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
if (this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j == 0)
{
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = -2;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = -3;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = -4;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = -5;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = -6;
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].from_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm - 1].to_j;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].PromoteToPiece = -7;
}
}
private void ListMoves_Rook(int pi, int pj, int pPositionNumber)
{
int i;
int j;
int nm;
bool RangeBlocked;
int ep;
bool WitchInfluence;
i = pi + 1;
j = pj;
RangeBlocked = false;
while (i < this.MyGame.NumberOfFiles & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
} else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
i++;
}
i = pi - 1;
j = pj;
RangeBlocked = false;
while (i > -1 & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
i--;
}
i = pi;
j = pj + 1;
RangeBlocked = false;
while (j < this.MyGame.NumberOfRanks & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
j++;
}
i = pi;
j = pj - 1;
RangeBlocked = false;
while (j > -1 & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
j--;
}
}
private void ListMoves_Bishop(int pi, int pj, int pPositionNumber)
{
int i;
int j;
int nm;
bool RangeBlocked;
int ep;
bool WitchInfluence;
i = pi + 1;
j = pj + 1;
RangeBlocked = false;
while (i < this.MyGame.NumberOfFiles & j < this.MyGame.NumberOfRanks & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
i++;
j++;
}
i = pi + 1;
j = pj - 1;
RangeBlocked = false;
while (i < this.MyGame.NumberOfFiles & j > -1 & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
i++;
j--;
}
i = pi - 1;
j = pj + 1;
RangeBlocked = false;
while (i > -1 & j < this.MyGame.NumberOfRanks & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
i--;
j++;
}
i = pi - 1;
j = pj - 1;
RangeBlocked = false;
while (i > -1 & j > -1 & RangeBlocked == false)
{
ep = this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour *
this.MyGame.MyPosition[pPositionNumber].ColourToMove;
WitchInfluence = false;
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == -1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1 &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == true)
{
WitchInfluence = true;
}
if (this.MyGame.MyPosition[pPositionNumber].ColourToMove == 1)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack = true;
}
if (ep <= 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
if (ep != 0 & WitchInfluence == false)
{
RangeBlocked = true;
}
i--;
j--;
}
}
private void ListMoves_Witch(int pi, int pj, int pPositionNumber)
{
int i;
int j;
int nm;
bool RangeBlocked;
RangeBlocked = false;
i = pi + 1;
j = pj;
if (i < this.MyGame.NumberOfFiles)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi + 2;
if (i < this.MyGame.NumberOfFiles)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi + 3;
while (i < this.MyGame.NumberOfFiles & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
i++;
}
RangeBlocked = false;
i = pi - 1;
j = pj;
if (i > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi - 2;
if (i > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi - 3;
while (i > -1 & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
i--;
}
RangeBlocked = false;
i = pi;
j = pj + 1;
if (j < this.MyGame.NumberOfRanks)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
j = pj + 2;
if (j < this.MyGame.NumberOfRanks)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
j = pj + 3;
while (j < this.MyGame.NumberOfRanks & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
j++;
}
RangeBlocked = false;
i = pi;
j = pj - 1;
if (j > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
j = pj - 2;
if (j > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
j = pj - 3;
while (j > -1 & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
j--;
}
RangeBlocked = false;
i = pi + 1;
j = pj + 1;
if (i < this.MyGame.NumberOfFiles & j < this.MyGame.NumberOfRanks)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi + 2;
j = pj + 2;
if (i < this.MyGame.NumberOfFiles & j < this.MyGame.NumberOfRanks)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi + 3;
j = pj + 3;
while (i < this.MyGame.NumberOfFiles & j < this.MyGame.NumberOfRanks & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
i++;
j++;
}
RangeBlocked = false;
i = pi + 1;
j = pj - 1;
if (i < this.MyGame.NumberOfFiles & j > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi + 2;
j = pj - 2;
if (i < this.MyGame.NumberOfFiles & j > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi + 3;
j = pj - 3;
while (i < this.MyGame.NumberOfFiles & j > -1 & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
i++;
j--;
}
RangeBlocked = false;
i = pi - 1;
j = pj - 1;
if (i > -1 & j > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi - 2;
j = pj - 2;
if (i > -1 & j > -1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi - 3;
j = pj - 3;
while (i > -1 & j > -1 & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
i--;
j--;
}
RangeBlocked = false;
i = pi - 1;
j = pj + 1;
if (i > -1 & j < this.MyGame.NumberOfRanks)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraWhiteWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].ExtraBlackWitchInfluence == false
& this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi - 2;
j = pj + 2;
if (i > -1 & j < this.MyGame.NumberOfRanks)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
}
i = pi - 3;
j = pj + 3;
while (i > -1 & j < this.MyGame.NumberOfRanks & RangeBlocked == false)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)i;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)j;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == 7)
{
RangeBlocked = true;
}
else
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence == false &
this.MyGame.MyPosition[pPositionNumber].MySquare[pi, pj].PieceTypeColour == -7)
{
RangeBlocked = true;
}
}
}
i--;
j++;
}
if (pi > 0 & pj > 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj - 2].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 2);
}
}
if (pi > 0 & pj < MyGame.NumberOfRanks - 2)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 1, pj + 2].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 2);
}
}
if (pi < this.MyGame.NumberOfFiles - 1 & pj > 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj - 2].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 2);
}
}
if (pi < this.MyGame.NumberOfFiles - 1 & pj < MyGame.NumberOfRanks - 2)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 1, pj + 2].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 1);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 2);
}
}
if (pi > 1 & pj > 0)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj - 1].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
}
}
if (pi > 1 & pj < MyGame.NumberOfRanks - 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi - 2, pj + 1].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi - 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
}
}
if (pi < this.MyGame.NumberOfFiles - 2 & pj > 0)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj - 1].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj - 1);
}
}
if (pi < this.MyGame.NumberOfFiles - 2 & pj < MyGame.NumberOfRanks - 1)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[pi + 2, pj + 1].PieceTypeColour == 0)
{
this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves++;
nm = this.MyGame.MyPosition[pPositionNumber].NumberOfFoundMoves - 1;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_i = (byte)pi;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].from_j = (byte)pj;
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_i = (byte)(pi + 2);
this.MyGame.MyPosition[pPositionNumber].MovesFromHere[nm].to_j = (byte)(pj + 1);
}
}
}
//Here the section ENDS that generates a list of moves from a given position
//Start of the section that enriches the position
private void Enrich_Initialize(int pPositionNumber)
{
int i1;
int j1;
this.MyGame.MyPosition[pPositionNumber].WhiteIsInCheck = false;
this.MyGame.MyPosition[pPositionNumber].BlackIsInCheck = false;
this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedTemp = false;
this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedTemp = false;
this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedTemp = false;
this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedTemp = false;
this.MyGame.MyPosition[pPositionNumber].WhiteKingLoci = 0;
this.MyGame.MyPosition[pPositionNumber].WhiteKingLocj = 0;
this.MyGame.MyPosition[pPositionNumber].BlackKingLoci = 0;
this.MyGame.MyPosition[pPositionNumber].BlackKingLocj = 0;
for (i1 = 0; i1 < this.MyGame.NumberOfFiles; i1++)
{
for (j1 = 0; j1 < this.MyGame.NumberOfRanks; j1++)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].WhiteWitchInfluence = false;
this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].BlackWitchInfluence = false;
this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].ExtraWhiteWitchInfluence = false;
this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].ExtraBlackWitchInfluence = false;
this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].IsAttackedByWhite = false;
this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].IsAttackedByBlack = false;
}
}
}
private void Enrich_CastleWhiteLeftBlockedTemp(int pPositionNumber)
{
int i;
int j;
j = 0;
//If castling is already blocked, stop evaluating this
if (this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedTemp == true |
this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedPerm == true)
{
return;
}
//All squares between King and Rook vacant, or there is a transparent piece
for (i = MyGame.MyPosition[pPositionNumber].WhiteKingLoci - 1; i > 0; i--)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence != true &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedTemp = true;
return;
}
}
//The squares where the King and Rook end should be really vacant
i = MyGame.MyPosition[pPositionNumber].WhiteKingLoci - this.MyGame.CastleDistance;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i + 1, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedTemp = true;
return;
}
//All squares from where the King starts to where the King ends should not be attacked
for (i = MyGame.MyPosition[pPositionNumber].WhiteKingLoci;
i >= MyGame.MyPosition[pPositionNumber].WhiteKingLoci - this.MyGame.CastleDistance; i--)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack)
{
this.MyGame.MyPosition[pPositionNumber].CastleWhiteLeftBlockedTemp = true;
return;
}
}
}
private void Enrich_CastleWhiteRightBlockedTemp(int pPositionNumber)
{
int i;
int j;
j = 0;
//If castling is already blocked, stop evaluating this
if (this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedTemp == true |
this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedPerm == true)
{
return;
}
//All squares between King and Rook vacant, or there is a transparent piece
for (i = MyGame.MyPosition[pPositionNumber].WhiteKingLoci + 1; i < this.MyGame.NumberOfFiles - 1; i++)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].WhiteWitchInfluence != true &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedTemp = true;
return;
}
}
//The squares where the King and Rook end should be really vacant
i = MyGame.MyPosition[pPositionNumber].WhiteKingLoci + this.MyGame.CastleDistance;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i - 1, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedTemp = true;
return;
}
//All squares from where the King starts to where the King ends should not be attacked
for (i = MyGame.MyPosition[pPositionNumber].WhiteKingLoci;
i <= MyGame.MyPosition[pPositionNumber].WhiteKingLoci + this.MyGame.CastleDistance; i++)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByBlack)
{
this.MyGame.MyPosition[pPositionNumber].CastleWhiteRightBlockedTemp = true;
return;
}
}
}
private void Enrich_CastleBlackLeftBlockedTemp(int pPositionNumber)
{
int i;
int j;
j = this.MyGame.NumberOfRanks - 1;
//If castling is already blocked, stop evaluating this
if (this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedTemp == true |
this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedPerm == true)
{
return;
}
//All squares between King and Rook vacant, or there is a transparent piece
for (i = MyGame.MyPosition[pPositionNumber].BlackKingLoci - 1; i > 0; i--)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence != true &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedTemp = true;
return;
}
}
//The squares where the King and Rook end should be really vacant
i = MyGame.MyPosition[pPositionNumber].BlackKingLoci - this.MyGame.CastleDistance;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i + 1, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedTemp = true;
return;
}
//All squares from where the King starts to where the King ends should not be attacked
for (i = MyGame.MyPosition[pPositionNumber].BlackKingLoci;
i >= MyGame.MyPosition[pPositionNumber].BlackKingLoci - this.MyGame.CastleDistance; i--)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite)
{
this.MyGame.MyPosition[pPositionNumber].CastleBlackLeftBlockedTemp = true;
return;
}
}
}
private void Enrich_CastleBlackRightBlockedTemp(int pPositionNumber)
{
int i;
int j;
j = this.MyGame.NumberOfRanks - 1;
//If castling is already blocked, stop evaluating this
if (this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedTemp == true |
this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedPerm == true)
{
return;
}
//All squares between King and Rook vacant, or there is a transparent piece
for (i = MyGame.MyPosition[pPositionNumber].BlackKingLoci + 1; i < this.MyGame.NumberOfFiles - 1; i++)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].BlackWitchInfluence != true &
this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedTemp = true;
return;
}
}
//The squares where the King and Rook end should be really vacant
i = MyGame.MyPosition[pPositionNumber].BlackKingLoci + this.MyGame.CastleDistance;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].PieceTypeColour != 0 |
this.MyGame.MyPosition[pPositionNumber].MySquare[i - 1, j].PieceTypeColour != 0)
{
this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedTemp = true;
return;
}
//All squares from where the King starts to where the King ends should not be attacked
for (i = MyGame.MyPosition[pPositionNumber].BlackKingLoci;
i <= MyGame.MyPosition[pPositionNumber].BlackKingLoci + this.MyGame.CastleDistance; i++)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i, j].IsAttackedByWhite)
{
this.MyGame.MyPosition[pPositionNumber].CastleBlackRightBlockedTemp = true;
return;
}
}
}
private void Enrich_IsInCheck(int pPositionNumber)
{
byte i1;
byte j1;
i1 = this.MyGame.MyPosition[pPositionNumber].WhiteKingLoci;
j1 = this.MyGame.MyPosition[pPositionNumber].WhiteKingLocj;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].IsAttackedByBlack == true)
{
this.MyGame.MyPosition[pPositionNumber].WhiteIsInCheck = true;
}
i1 = this.MyGame.MyPosition[pPositionNumber].BlackKingLoci;
j1 = this.MyGame.MyPosition[pPositionNumber].BlackKingLocj;
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].IsAttackedByWhite == true)
{
this.MyGame.MyPosition[pPositionNumber].BlackIsInCheck = true;
}
}
private void EnrichWitchInfluence(int pPositionNumber)
{
int i1;
int j1;
int i2;
int j2;
for (i1=0;i1 < this.MyGame.NumberOfFiles;i1++)
{
for (j1=0;j1 < this.MyGame.NumberOfRanks;j1++)
{
if(this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].PieceTypeColour == 7)
{
for (i2 = Math.Max(0, i1 - 1); i2 < Math.Min(this.MyGame.NumberOfFiles, i1 + 2); i2++)
{
for (j2 = Math.Max(0, j1 - 1); j2 < Math.Min(this.MyGame.NumberOfRanks, j1 + 2); j2++)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].WhiteWitchInfluence == true)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].ExtraWhiteWitchInfluence = true;
} else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].WhiteWitchInfluence = true;
}
}
}
}
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i1, j1].PieceTypeColour == -7)
{
for (i2 = Math.Max(0, i1 - 1); i2 < Math.Min(this.MyGame.NumberOfFiles, i1 + 2); i2++)
{
for (j2 = Math.Max(0, j1 - 1); j2 < Math.Min(this.MyGame.NumberOfRanks, j1 + 2); j2++)
{
if (this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].BlackWitchInfluence == true)
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].ExtraBlackWitchInfluence = true;
}
else
{
this.MyGame.MyPosition[pPositionNumber].MySquare[i2, j2].BlackWitchInfluence = true;
}
}
}
}
}
}
}
//End of the section that enriches the position
}
}