public Piece( int nRow, int nCol, bool bBlack, Table _parentTable ) { m_position = new Point( nRow, nCol ); m_bBlack = bBlack; m_parentTable = _parentTable; m_vetPossibleMovements = new List<Point>( ); }
public Play getCPUPlay(Table table) { negamax(table, 2); if (m_winnerTable == null) return null; Play play = m_winnerTable - table; m_winnerTable = null; return play; }
public Knight(int _posX, int _posY, bool bBlack, Table _parentTable) : base(_posX, _posY, bBlack, _parentTable) { }
//protected PieceMovement m_movement; // static Texture2D selfImageBlack; // static Texture2D selfImageWhite; // Constructors public Piece( bool bBlack, Table _parentTable ) : this(0, 0, bBlack, _parentTable) { }
private int evaluateTable(Table table) { int nValue = 0; for (int nRow = 0; nRow < table.TableSize; ++nRow) { for (int nCol = 0; nCol < table.TableSize; ++nCol) { Piece piece = table.getTableSquare(nCol, nRow).Piece; if (piece == null) continue; if (m_bBlack != piece.isBlack) { if (piece is Queen) { nValue += 50; } else if (piece is Bishop) { nValue += 25; } else if (piece is Rook) { nValue += 20; } else if (piece is Knight) { nValue += 10; } else if (piece is Pawn) { nValue += 5; } } else { if (piece is Queen) { nValue += 30; } else if (piece is Bishop) { nValue += 15; } else if (piece is Rook) { nValue += 10; } else if (piece is Knight) { nValue += 5; } else if (piece is Pawn) { nValue += 2; } } } } return nValue; }
private int negamax(Table table, int depth) { if (/*table.IsInCheckMate(m_bBlack) || */(depth == 0)) { //m_winnerTable = table; return evaluateTable(table); } else { if ((depth % 2) == 1) m_bTeamTemp = m_bBlack; else m_bTeamTemp = !m_bBlack; int alpha = int.MinValue; List<Table> lstTables = generateTables(table); foreach (Table childTable in lstTables) { int alphaTmp = Math.Max(alpha, -negamax(childTable, depth - 1)); if (alphaTmp > alpha) { alpha = alphaTmp; m_winnerTable = childTable; } } return alpha; } /* ROTINA minimax(nó, profundidade) SE nó é um nó terminal OU profundidade = 0 ENTÃO RETORNE o valor da heurística do nó SENÃO α ← -∞ { a avaliação é idêntica para ambos os jogadores } PARA CADA filho DE nó α ← max(α, -minimax(filho, profundidade-1)) FIM PARA RETORNE α FIM SE FIM ROTINA */ }
private List<Table> generateTables(Table table) { List<Table> lstTables = new List<Table>(); for (int nRow = 0; nRow < table.TableSize; ++nRow) { for (int nCol = 0; nCol < table.TableSize; ++nCol) { Table.TableSquare tableSquare = table.getTableSquare(nRow, nCol); // Verify if the is a piece in this square. if (tableSquare.Piece == null) continue; // Verify if the piece is mine. if (tableSquare.Piece.isBlack != m_bTeamTemp) continue; List<Point> lstPositions = tableSquare.Piece.vetPossibleMovements; foreach (Point position in lstPositions) { Play play = new Play(); play.oldPosition = new Point(nRow, nCol); play.newPosition = position; Table newTable = table + play; lstTables.Add(newTable); } } } return lstTables; }
public Bishop(int _posX, int _posY, bool bBlack, Table _parentTable ) : base(_posX, _posY, bBlack, _parentTable) { //m_movement = new PieceMovement(); }
public Pawn(int _posX, int _posY, bool bBlack, Table _parentTable ) : base(_posX, _posY, bBlack, _parentTable) { m_bFirstMove = true; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); m_rectTable.X = 0; m_rectTable.Y = 0; m_rectTable.Width = 640; m_rectTable.Height = 640; m_graphics.PreferredBackBufferHeight = 640; m_graphics.PreferredBackBufferWidth = 640; m_graphics.ApplyChanges(); m_listTargetsMovements = new List<Point>(); m_gameTable = new Table(); m_bPieceSelected = false; m_bResetGame = true; m_bInitGame = false; m_bCanBePressed = false; m_updateCounts = 0; m_stateSplash = SPLASH_STATES.OPEN; m_playTurn = Play_Turn.White_Turn; m_bPlayerBlackCPU = true; m_bPlayerWhiteCPU = false; m_cpuPlayer = new MiniMax(); m_cpuPlayer.setTeam(m_bPlayerBlackCPU); // CPU is with Black pieces. m_DeadBlackSpaces = new Rectangle[TOTAL_BLACK_PIECES]; m_DeadWhiteSpaces = new Rectangle[TOTAL_WHITE_PIECES]; InitializeDeadSpaces(); m_gameTable.calculateWhitePiecesPosition( false ); m_rectPlayNow.Height = 100; m_rectPlayNow.Width = 20; m_rectPlayNow.X = (36 / 2) - (m_rectPlayNow.Width/2); m_rectPlayNow.Y = (640 / 2) - (m_rectPlayNow.Height/2); m_rectButton.Height = 20; m_rectButton.Width = m_rectPlayNow.Width; m_rectButton.X = (36 / 2) - (m_rectButton.Width / 2); m_rectButton.Y = ((m_rectPlayNow.Y + m_rectPlayNow.Height) + 4); m_rectSplashScreens.Height = 300; m_rectSplashScreens.Width = 400; m_rectSplashScreens.X = (m_rectTable.Width / 2) - (m_rectSplashScreens.Width / 2); m_rectSplashScreens.Y = (m_rectTable.Height / 2) - (m_rectSplashScreens.Height / 2); }
public Queen(int _posX, int _posY, bool bBlack, Table _parentTable) : base(_posX, _posY, bBlack, _parentTable) { }