Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
2.6 kB
10
Indexable
Never
#pragma once
/*
    This header file contains th ChessGame class.
    contains the whole game.
*/

#ifndef _CHESSGAME_H
#define _CHESSGAME_H

#include <SFML/Graphics.hpp>
#include <array>
#include <vector>
#include <iostream>
#include "board.h"
#include "piece.h"

class ChessGame : public sf::Drawable {
public:
    int modeGame = 0;
    Board board;
    std::array<Piece, 16> white;
    std::array<Piece, 16> black;
    std::array<Piece, 16> whitePieces;
    std::array<Piece, 16> blackPieces;
    Piece* selectedPiece;
    Piece* selectedPiece1;
    Piece* selectedPiece2;
    Piece* selectedPiece3;
    Piece* selectedPiece4;
    Piece* save;
    std::vector<sf::RectangleShape> possibleMovesSquares;
    std::string lastMove;

    sf::RectangleShape infoRestart;

    sf::Font font;
    sf::Text textRestart;
    sf::Text textTurn;
    sf::Text textSituation;
    sf::Text textLastMove;

    int xxx = 0;

    bool selected;
    bool playerTurn; // true = White turn, false = Black Turn
    bool playerTurnCheck;
    bool mate;
    int turn;

    void createMovesSquares();

    void calcPossibleMoves();
    void calcKingMoves(Piece* tmpPiece);
    void calcQueenMoves(Piece* tmpPiece);
    void calcRookMoves(Piece* tmpPiece);
    void calcBishopMoves(Piece* tmpPiece);
    void calcKnightMoves(Piece* tmpPiece);
    void calcPawnMoves(Piece* tmpPiece);
    void calcCastling(Piece* tmpPiece);

    // khoi tao stack va setup undo
    void undo(bool check);
    int saveMove[2000] = { 0 };
    int st= 0;
    int saveDead[2000] = { 0 };
    int savePawn[2000];
    int front(int SaveMove[]) { return SaveMove[st]; }
    void push(int SaveMove[], int value) { SaveMove[st] = value; }
    void del(int SaveMove[]) { SaveMove[st] = 0; }

    // khoi tao black bot
    int minimax(const std::array<Piece, 16>& white, const std::array<Piece, 16>& black, int depth, int alpha, int beta, bool maximizingPlayer);
    void blackBot();
    int getScore(const std::array<Piece, 16>& white, const std::array<Piece, 16>& black);
    void killChess(int go, bool check);
    int Score();

    void eraseMoves(Piece* tmpPiece);

    void checkMate();

    void updateInfo();

    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

    ChessGame(sf::Color bordCol1, sf::Color bordCol2);

    bool getSelected() { return selected; }

    bool getMate() { return mate; }

    bool selectPiece(int pos);

    void moveSelected(int pos);

    void restart();



};


#endif