/// <summary> /// Transform a ChessBoard piece into a ChessPiece enum /// </summary> /// <param name="ePiece"></param> /// <returns></returns> private static ChessPiece GetChessPieceFromPiece(Pieco ePiece) { ChessPiece eRetVal; switch (ePiece) { case Pieco.Pawn | Pieco.White: eRetVal = ChessPiece.White_Pawn; break; case Pieco.Knight | Pieco.White: eRetVal = ChessPiece.White_Knight; break; case Pieco.Bishop | Pieco.White: eRetVal = ChessPiece.White_Bishop; break; case Pieco.Rook | Pieco.White: eRetVal = ChessPiece.White_Rook; break; case Pieco.Queen | Pieco.White: eRetVal = ChessPiece.White_Queen; break; case Pieco.King | Pieco.White: eRetVal = ChessPiece.White_King; break; case Pieco.Pawn | Pieco.Black: eRetVal = ChessPiece.Black_Pawn; break; case Pieco.Knight | Pieco.Black: eRetVal = ChessPiece.Black_Knight; break; case Pieco.Bishop | Pieco.Black: eRetVal = ChessPiece.Black_Bishop; break; case Pieco.Rook | Pieco.Black: eRetVal = ChessPiece.Black_Rook; break; case Pieco.Queen | Pieco.Black: eRetVal = ChessPiece.Black_Queen; break; case Pieco.King | Pieco.Black: eRetVal = ChessPiece.Black_King; break; default: eRetVal = ChessPiece.None; break; } return(eRetVal); }
/* * /// <summary> * /// OnQweryPawnPromotionType: Trigger the QueryPawnPromotionType event * /// </summary> * /// <param name="e"> Event arguments</param> * protected virtual void OnQueryPawnPromotionType(QueryPawnPromotionTypeEventArgs e) { * if (QueryPawnPromotionType != null) { * QueryPawnPromotionType(this, e); * } * } */ #endregion #region Methods /* * /// <summary> * /// Create a new game using the specified list of moves * /// </summary> * /// <param name="chessBoardStarting"> Starting board or null if standard board</param> * /// <param name="listMove"> List of moves</param> * /// <param name="eNextMoveColor"> Color starting to play</param> * /// <param name="strWhitePlayerName"> Name of the player playing white pieces</param> * /// <param name="strBlackPlayerName"> Name of the player playing black pieces</param> * /// <param name="eWhitePlayerType"> Type of player playing white pieces</param> * /// <param name="eBlackPlayerType"> Type of player playing black pieces</param> * /// <param name="spanPlayerWhite"> Timer for white</param> * /// <param name="spanPlayerBlack"> Timer for black</param> * public virtual void CreateGameFromMove(ChessBoard chessBoardStarting, * List<ChessBoard.MovePosS> listMove, * ChessBoard.PlayerColorE eNextMoveColor, * string strWhitePlayerName, * string strBlackPlayerName, * PgnParser.PlayerTypeE eWhitePlayerType, * PgnParser.PlayerTypeE eBlackPlayerType, * TimeSpan spanPlayerWhite, * TimeSpan spanPlayerBlack) { * m_board.CreateGameFromMove(chessBoardStarting, * listMove, * eNextMoveColor); * if (m_moveListUI != null) { * m_moveListUI.Reset(m_board); * } * WhitePlayerName = strWhitePlayerName; * BlackPlayerName = strBlackPlayerName; * WhitePlayerType = eWhitePlayerType; * BlackPlayerType = eBlackPlayerType; * OnUpdateCmdState(System.EventArgs.Empty); * m_gameTimer.ResetTo(m_board.NextMoveColor, * spanPlayerWhite.Ticks, * spanPlayerBlack.Ticks); * m_gameTimer.Enabled = true; * Refresh(false); // bForceRefresh * } */ /// <summary> /// Set the piece in a case. Can only be used in design mode. /// </summary> public void SetCaseValue(int iPos, Pieco ePiece) { if (BoardDesignMode) { m_board[iPos] = ePiece; RefreshCell(iPos); } }
public Mova(bool pcolo, Pieco pfigo, int pif, int pit, MovoTypo pmt) { coala = pcolo; figo = pfigo; fromo = pif; tomo = pit; typo = pmt; shorto = null; }
public Mova(bool pcolo, Pieco pfigo, int pif, int pit, MovoTypo pmt) { coala = pcolo; figo = pfigo; fromo = pif; tomo = pit; typo = pmt; shorto = null; }
/// <summary> /// Gets the specified piece /// </summary> /// <param name="ePiece"></param> /// <returns> /// User control expressing the piece /// </returns> public UserControl this[Pieco ePiece] { get { UserControl userControlRetVal; ChessPiece eChessPiece; eChessPiece = GetChessPieceFromPiece(ePiece); userControlRetVal = (eChessPiece == ChessPiece.None) ? null : LoadPiece(eChessPiece); return(userControlRetVal); } }
/// <summary> /// Gets the specified piece /// </summary> /// <param name="ePiece"></param> /// <returns> /// User control expressing the piece /// </returns> public UserControl this[Pieco ePiece] { get { UserControl userControlRetVal; ChessPiece eChessPiece; eChessPiece = GetChessPieceFromPiece(ePiece); userControlRetVal = (eChessPiece == ChessPiece.None) ? null : LoadPiece(eChessPiece); return(userControlRetVal); } }
/// <summary> /// Set the chess piece control /// </summary> /// <param name="iBoardPos"> Board position</param> /// <param name="ePiece"> Piece</param> private void SetPieceControl(int iBoardPos, Pieco ePiece) { Border border; UserControl userControlPiece; border = m_arrBorder[iBoardPos]; userControlPiece = m_pieceSet[ePiece]; if (userControlPiece != null) { userControlPiece.Margin = (border.BorderThickness.Top == 0) ? new Thickness(3) : new Thickness(1); } m_arrPiece[iBoardPos] = ePiece; border.Child = userControlPiece; }
/// <summary> /// Модификация от 29 июля 2015 года /// Заложен 29 июля 2015 года /// </summary> /// <param name="ppb"></param> /// <param name="coloro"></param> /// <param name="prok"></param> /// <param name="penp"></param> /// <param name="penf"></param> /// <param name="ppmv"></param> /// <param name="pnum"></param> public pozo(Pieco[] ppb, bool coloro, Caslo prok, bool penp, int penf, int ppmv, int pnum) { pBoard = new Pieco[64]; for (int i = 0; i < 64; i++) { pBoard[i] = ppb[i]; } whitomv = coloro; rokko = prok; enpasso = penp; enfield = penf; pustomv = ppmv; numbero = pnum; qava = -1; pzu = null; controllomova = null; }
/// <summary> /// Модификация от 26 августа 2015 года /// Заложен 24 июля 2015 года /// </summary> /// <param name="fg"></param> /// <param name="pf"></param> /// <param name="pt"></param> /// <returns></returns> private bool IsCanMove(Pieco fg, int pf, int pt, bool vzyatie) { bool reto = false; switch(fg & Pieco.PieceMask) { case Pieco.Queen: foreach( int[] aa in s_pppiCaseMoveDiagLine[pf]) { if( IsAvailableFieldOnLineOrDiagonal(aa, pt) ) { reto = true; break; } } break; case Pieco.Rook: foreach (int[] aa in s_pppiCaseMoveLine[pf]) { if (IsAvailableFieldOnLineOrDiagonal(aa, pt)) { reto = true; break; } } break; case Pieco.Bishop: foreach (int[] aa in s_pppiCaseMoveDiagonal[pf]) { if (IsAvailableFieldOnLineOrDiagonal(aa, pt)) { reto = true; break; } } break; case Pieco.Knight: if( s_ppiCaseMoveKnight[pf].Contains(pt) ) { reto = true; } break; case Pieco.King: if (s_ppiCaseMoveKing[pf].Contains(pt)) { reto = true; } break; case Pieco.Pawn: if (vzyatie) { int[] bb = whitomv ? s_ppiCaseWhitePawnCanAttackFrom[pt] : s_ppiCaseBlackPawnCanAttackFrom[pt]; if (bb.Contains(pf)) { reto = true; } } else { if (whitomv) { if (pt / 8 == 3) { if ((pf == pt - 16) && pBoard[pt - 8] == Pieco.None) { reto = true; } } if (pf == pt - 8) { reto = true; } } else { if (pt / 8 == 4) { if ((pf == pt + 16) && pBoard[pt + 8] == Pieco.None) { reto = true; } } if (pf == pt + 8) { reto = true; } } } break; default: break; } return reto; }
private bool IsAvailableMove(int pif, int pit, Pieco fipa, MovoTypo pmt) { bool reto = false; PozoUtils nnp = new PozoUtils(pBoard, whitomv, pif, pit, fipa, pmt, true); reto = nnp.IsNoCheck(); return reto; }
/// <summary> /// Целочисленная проверка на шах с целью зафиксировать откуда шахуют /// Модификация от 3 августа 2015 года /// Заложен 3 августа 2015 года /// </summary> /// <param name="ppiCaseMoveList"></param> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> private int FieldFromCheckTwoPeace(int[][] ppiCaseMoveList, Pieco p1, Pieco p2) { int reto = -1; Pieco curro; foreach (int[] piMoveList in ppiCaseMoveList) { foreach (int iNewPos in piMoveList) { curro = pBoard[iNewPos]; if (curro != Pieco.None) { if (curro == p1 || curro == p2) { reto = iNewPos; } break; } } } return reto; }
/// <summary> /// Целочисленная проверка на шах с целью зафиксировать откуда шахуют /// Модификация от 3 августа 2015 года /// Заложен 3 августа 2015 года /// </summary> /// <param name="piCaseMoveList"></param> /// <param name="pp"></param> /// <returns></returns> private int FieldFromCheckOnePeace(int[] piCaseMoveList, Pieco pp) { int reto = -1; foreach (int iNewPos in piCaseMoveList) { if (pBoard[iNewPos] == pp) { reto = iNewPos; break; } } return reto; }
private bool CheckFromTwoPeace(int[][] ppiCaseMoveList, Pieco p1, Pieco p2) { bool reto = false; Pieco curro; foreach (int[] piMoveList in ppiCaseMoveList) { foreach (int iNewPos in piMoveList) { curro = pBoard[iNewPos]; if (curro != Pieco.None) { if (curro == p1 || curro == p2) { reto = true; } break; } } } return reto; }
/// <summary> /// Перечень полей, откуда данная фигура может прийти (возможно и со взятием - смотри параметр pmt) на указанное поле /// Модификация от 26 августа 2015 года /// Заложен 24 июля 2015 года /// </summary> /// <param name="who">Фигура, для которой составляется список</param> /// <param name="fildo">Поле, куда стремится указанная фигура</param> /// <param name="pmt">Тип - просто ход или даже взятие</param> /// <returns>Список, предполагающий максимум две начальные точки, хотя теоретически никто не отменял три и более. Вопрос реальности этого в жизни!!!</returns> public List<int> ListFieldsFromAttackedThisField(Pieco who, int fildo, MovoTypo pmt) { List<int> reto = new List<int>(2); //Не больше 2 if (!whitomv) { who |= Pieco.Black; } for (int i = 0; i < 64; i++) { if (pBoard[i] == who) { if( IsCanMove(who, i, fildo, (pmt & (~MovoTypo.MoveTypeMask)) == MovoTypo.PieceEaten) ) { if (IsAvailableMove(i, fildo, who, pmt)) { reto.Add(i); } } } } return reto; }
/// <summary> /// Transform a ChessBoard piece into a ChessPiece enum /// </summary> /// <param name="ePiece"></param> /// <returns></returns> private static ChessPiece GetChessPieceFromPiece(Pieco ePiece) { ChessPiece eRetVal; switch (ePiece) { case Pieco.Pawn | Pieco.White: eRetVal = ChessPiece.White_Pawn; break; case Pieco.Knight | Pieco.White: eRetVal = ChessPiece.White_Knight; break; case Pieco.Bishop | Pieco.White: eRetVal = ChessPiece.White_Bishop; break; case Pieco.Rook | Pieco.White: eRetVal = ChessPiece.White_Rook; break; case Pieco.Queen | Pieco.White: eRetVal = ChessPiece.White_Queen; break; case Pieco.King | Pieco.White: eRetVal = ChessPiece.White_King; break; case Pieco.Pawn | Pieco.Black: eRetVal = ChessPiece.Black_Pawn; break; case Pieco.Knight | Pieco.Black: eRetVal = ChessPiece.Black_Knight; break; case Pieco.Bishop | Pieco.Black: eRetVal = ChessPiece.Black_Bishop; break; case Pieco.Rook | Pieco.Black: eRetVal = ChessPiece.Black_Rook; break; case Pieco.Queen | Pieco.Black: eRetVal = ChessPiece.Black_Queen; break; case Pieco.King | Pieco.Black: eRetVal = ChessPiece.Black_King; break; default: eRetVal = ChessPiece.None; break; } return(eRetVal); }
public PozoUtils(Pieco[] pp, bool pcolor, Caslo pr, bool v, int penp) { pBoard = pp; whitomv = pcolor; rokko = pr; enpasso = v; enfield = penp; }
/// <summary> /// Модификация от 26 августа 2015 года /// Заложен июнь 2015 года /// Функция перегружена из-за неоднозначности передаваемого цвета /// </summary> /// <param name="pp"></param> /// <param name="pcolor">Новый цвет - создаваемой уже после хода позиции /// Но это не всегда. При вызове из функции IsAvailableMove цвет старый и вся эта позиция нужна только /// для проверки на неполучение шаха после сделанного хода</param> /// <param name="pif"></param> /// <param name="pit"></param> /// <param name="fipa"></param> /// <param name="pmt"></param> /// <param name="SvoyChuzhoy">Цвет свой (true) или чужой для хода</param> public PozoUtils(Pieco[] pp, bool pcolor, int pif, int pit, Pieco fipa, MovoTypo pmt, bool SvoyChuzhoy) { pBoard = new Pieco[64]; Pieco pkinga = pcolor ? Pieco.King : (Pieco.King | Pieco.Black); for (int i = 63; i >= 0; i--) { if (pp[i] == pkinga) { kingo = i; } pBoard[i] = pp[i]; } if (fipa == pkinga) { kingo = pit; } //Предположительно неразумная вставка. Условие никогда не может быть выполнено. Ха ха. Цвета разные. //так как короли разные у фигуры еще прошлый король, а у pkinga уже новый. pBoard[pif] = Pieco.None; pBoard[pit] = fipa; if ((pmt & MovoTypo.EnPassant) > 0) { int oldpawn = 0; if (SvoyChuzhoy) { oldpawn = pit + (pcolor ? -8 : 8); } else { oldpawn = pit + (pcolor ? 8 : -8); } pBoard[oldpawn] = Pieco.None; } if (pmt == MovoTypo.Castle) { //Страшная хардкорщина. Но на самом деле нормально. switch (pit) { case 1: pBoard[2] = pBoard[0]; pBoard[0] = Pieco.None; break; case 5: pBoard[4] = pBoard[7]; pBoard[7] = Pieco.None; break; case 57: pBoard[58] = pBoard[56]; pBoard[56] = Pieco.None; break; case 61: pBoard[60] = pBoard[63]; pBoard[63] = Pieco.None; break; } } bool prevrashenye = (SvoyChuzhoy) ? !pcolor : pcolor; if ((pmt & MovoTypo.MoveTypeMask) == MovoTypo.PawnPromotionToQueen) { pBoard[pit] = Pieco.Queen | (prevrashenye ? Pieco.Black : Pieco.White); } else if ((pmt & MovoTypo.MoveTypeMask) == MovoTypo.PawnPromotionToRook) { pBoard[pit] = Pieco.Rook | (prevrashenye ? Pieco.Black : Pieco.White); } else if ((pmt & MovoTypo.MoveTypeMask) == MovoTypo.PawnPromotionToKnight) { pBoard[pit] = Pieco.Knight | (prevrashenye ? Pieco.Black : Pieco.White); } else if ((pmt & MovoTypo.MoveTypeMask) == MovoTypo.PawnPromotionToBishop) { pBoard[pit] = Pieco.Bishop | (prevrashenye ? Pieco.Black : Pieco.White); } if (fipa == (Pieco.Pawn | Pieco.White) && ((pif - pit) == 16)) { if ((pit % 8 > 0 && pBoard[pit - 1] == (Pieco.Pawn | Pieco.Black)) || (pit % 8 < 7 && pBoard[pit + 1] == (Pieco.Pawn | Pieco.Black))) { enpasso = true; enfield = pit - 24; } } else if (fipa == (Pieco.Pawn | Pieco.Black) && (pif - pit == 16)) { if ((pit % 8 > 0 && pBoard[pit - 1] == (Pieco.Pawn | Pieco.White)) || (pit % 8 < 7 && pBoard[pit + 1] == (Pieco.Pawn | Pieco.White))) { enpasso = true; enfield = pit - 24; } } whitomv = pcolor; }
/* /// <summary> /// Create a new game using the specified list of moves /// </summary> /// <param name="chessBoardStarting"> Starting board or null if standard board</param> /// <param name="listMove"> List of moves</param> /// <param name="eNextMoveColor"> Color starting to play</param> /// <param name="strWhitePlayerName"> Name of the player playing white pieces</param> /// <param name="strBlackPlayerName"> Name of the player playing black pieces</param> /// <param name="eWhitePlayerType"> Type of player playing white pieces</param> /// <param name="eBlackPlayerType"> Type of player playing black pieces</param> /// <param name="spanPlayerWhite"> Timer for white</param> /// <param name="spanPlayerBlack"> Timer for black</param> public virtual void CreateGameFromMove(ChessBoard chessBoardStarting, List<ChessBoard.MovePosS> listMove, ChessBoard.PlayerColorE eNextMoveColor, string strWhitePlayerName, string strBlackPlayerName, PgnParser.PlayerTypeE eWhitePlayerType, PgnParser.PlayerTypeE eBlackPlayerType, TimeSpan spanPlayerWhite, TimeSpan spanPlayerBlack) { m_board.CreateGameFromMove(chessBoardStarting, listMove, eNextMoveColor); if (m_moveListUI != null) { m_moveListUI.Reset(m_board); } WhitePlayerName = strWhitePlayerName; BlackPlayerName = strBlackPlayerName; WhitePlayerType = eWhitePlayerType; BlackPlayerType = eBlackPlayerType; OnUpdateCmdState(System.EventArgs.Empty); m_gameTimer.ResetTo(m_board.NextMoveColor, spanPlayerWhite.Ticks, spanPlayerBlack.Ticks); m_gameTimer.Enabled = true; Refresh(false); // bForceRefresh } */ /// <summary> /// Set the piece in a case. Can only be used in design mode. /// </summary> public void SetCaseValue(int iPos, Pieco ePiece) { if (BoardDesignMode) { m_board[iPos] = ePiece; RefreshCell(iPos); } }
private bool CheckFromOnePeace(int[] piCaseMoveList, Pieco pp) { bool reto = false; foreach (int iNewPos in piCaseMoveList) { if (pBoard[iNewPos] == pp) { reto = true; break; } } return reto; }
/// <summary> /// Set the chess piece control /// </summary> /// <param name="iBoardPos"> Board position</param> /// <param name="ePiece"> Piece</param> private void SetPieceControl(int iBoardPos, Pieco ePiece) { Border border; UserControl userControlPiece; border = m_arrBorder[iBoardPos]; userControlPiece = m_pieceSet[ePiece]; if (userControlPiece != null) { userControlPiece.Margin = (border.BorderThickness.Top == 0) ? new Thickness(3) : new Thickness(1); } m_arrPiece[iBoardPos] = ePiece; border.Child = userControlPiece; }
/// <summary> /// Constructor /// </summary> /// <param name="iPos"> Position of the square</param> /// <param name="ePiece"> Piece</param> public QueryPieceEventArgs(int iPos, Pieco ePiece) { Pos = iPos; Piece = ePiece; }
/// <summary> /// Constructor /// </summary> /// <param name="iPos"> Position of the square</param> /// <param name="ePiece"> Piece</param> public QueryPieceEventArgs(int iPos, Pieco ePiece) { Pos = iPos; Piece = ePiece; }