Browse Source

worked on uci interface

nicolaswinkler 7 years ago
parent
commit
73d1b4ec2b
4 changed files with 82 additions and 8 deletions
  1. 47 1
      src/MoveGeneration.cpp
  2. 2 1
      src/MoveGeneration.h
  3. 10 2
      src/UciParser.cpp
  4. 23 4
      src/UciParser.h

+ 47 - 1
src/MoveGeneration.cpp

@@ -7,12 +7,58 @@ template class PawnPushGenerator<WHITE_SIDE>;
 template class PawnPushGenerator<BLACK_SIDE>;
 
 
-std::string chessy::Move::asString(void) const
+std::string Move::asString(void) const
 {
     return origin.getName() + "-" + destination.getName();
 }
 
 
+std::vector<Move> MoveGenerator::generatePossibleMoves(void) const
+{
+    const ChessGame& cg = game;
+    Bitboard whites = cg.getBoard().getWhites();
+    Bitboard blacks = cg.getBoard().getBlacks();
+    std::vector<Move> ret;
+    PawnPushGenerator<BLACK_SIDE> mg{ cg };
+    for (auto push : mg)
+        ret.push_back(push);
+    PositionSet knights = cg.getBoard().getBlackKnights();
+    for (auto knight : knights) {
+        for (auto pos : KnightMoveGenerator{ knight, blacks }) {
+            ret.push_back(Move{ knight, pos });
+        }
+    }
+
+    PositionSet bishops = cg.getBoard().getBlackBishops();
+    for (auto bishop : bishops) {
+        for (auto pos : PrimitiveBishopMoveGenerator{ bishop, whites, blacks }) {
+            ret.push_back(Move{ bishop, pos });
+        }
+    }
+
+    PositionSet rooks = cg.getBoard().getBlackRooks();
+    for (auto rook : rooks) {
+        for (auto pos : PrimitiveRookMoveGenerator{ rook, whites, blacks }) {
+            //cout << "rook: " << Move(rook, pos).asString() << endl;
+        }
+    }
+
+    PositionSet queens = cg.getBoard().getBlackQueens();
+    for (auto queen : queens) {
+        for (auto pos : PrimitiveQueenMoveGenerator{ queen, whites, blacks }) {
+            //cout << "queen: " << Move(queen, pos).asString() << endl;
+        }
+    }
+
+    Bitboard king = cg.getBoard().getBlackKings();
+    Index kingIndex = king.getLeastSignificantBit();
+    for (auto pos : KingMoveGenerator{ king, blacks }) {
+        //cout << "king: " << Move(kingIndex, pos).asString() << endl;
+    }
+    return ret;
+}
+
+
 template<int side>
 typename PawnPushGenerator<side>::MoveIterator PawnPushGenerator<side>::begin(void) const
 {

+ 2 - 1
src/MoveGeneration.h

@@ -3,6 +3,7 @@
 
 #include "BitBoard.h"
 #include <string>
+#include <vector>
 #include <array>
 
 namespace chessy
@@ -54,7 +55,7 @@ public:
     inline MoveGenerator(const ChessGame& game) :
         game{ game } {}
 
-
+    std::vector<Move> generatePossibleMoves(void) const;
 };
 
 

+ 10 - 2
src/UciParser.cpp

@@ -29,7 +29,7 @@ int UciParser::parse(istream& in, ostream& out)
 
 int UciParser::executeLine(const string& line)
 {
-    stringstream s{ line };
+    istringstream s{ line };
     string token;
     string command;
     vector<string> args;
@@ -51,6 +51,7 @@ int UciParser::executeCommand(const string& command,
     }
     catch (out_of_range& oor) {
         // no handler for command -> invalid command
+        
         return 1;
     }
 }
@@ -60,6 +61,7 @@ void UciParser::sendCommand(const std::string& command,
 {
     cout << command;
     std::for_each(args.begin(), args.end(), [] (auto& x) { cout << " " << x; });
+    cout << endl;
 }
 
 
@@ -77,17 +79,23 @@ void UciParser::debug(const std::vector<std::string>& args)
 
 void UciParser::isready(const std::vector<std::string>& args)
 {
-    sendCommand(READYOK);
+    sendCommand("readyok");
 }
 
 
 void UciParser::setoption(const std::vector<std::string>& args)
 {
+    if (args.size() < 2)
+        return;
+    if (args[0] != "name")
+        return;
+    
 }
 
 
 void UciParser::ucinewgame(const std::vector<std::string>& args)
 {
+    return;
 }
 
 

+ 23 - 4
src/UciParser.h

@@ -7,6 +7,24 @@
 #include <algorithm>
 #include <map>
 
+
+struct Option
+{
+    std::string name;
+    std::string type;
+    std::string defaultValue;
+    std::string min;
+    std::string max;
+};
+
+
+class OptionsManager
+{
+public:
+    OptionsManager(void);
+};
+
+
 /*!
  * manages the communication with a UCI connection
  */
@@ -15,11 +33,12 @@ class UciParser
     using CommandHandler = void(UciParser::*)(const std::vector<std::string>&);
     static const std::map<std::string, CommandHandler> commandHandlers;
 
-    static constexpr const char* UCIOK = "uciok";
-    static constexpr const char* READYOK = "readyok";
-
+    std::istream& in;
+    std::ostream& out;
+    OptionsManager optionsManager;
 public:
-    UciParser(void) = default;
+    inline UciParser(std::istream& in = std::cin, std::ostream& out = std::cout) :
+        in{ in }, out{ out } {}
     virtual ~UciParser(void) = default;
 
     virtual int parse(std::istream& in, std::ostream& out);