File size: 925 Bytes
6260b52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once
#include <string>
#include <set>
#include <memory>

// just basic validation
// fixme: missing en passant, castling, promotion, etc.
struct State;
class Piece;
class Chessboard {
public:
    Chessboard();
    ~Chessboard();
    std::string process(const std::string& command);
    std::string stringifyBoard();
    const std::string& grammar() { return m_grammar; }
    const std::string& prompt() { return m_prompt; }
    void setPrompt(const std::string& prompt);
private:
    bool parseCommand(const std::string& command, Piece*& piece, char& pos_to);
    bool move(Piece& piece, char pos);
    void flagUpdates(char pos_from, char pos_to);
    void updatePins(Piece& piece);
    void detectChecks();
    void setGrammar();

    std::unique_ptr<State> m_state;
    std::set<char> m_allowedInCheck;
    bool m_inCheck = false;
    int m_moveCounter = 0;
    std::string m_grammar;
    std::string m_prompt;
};