Nicolas Winkler 8 سال پیش
والد
کامیت
86ab3fb1a3
4فایلهای تغییر یافته به همراه54 افزوده شده و 18 حذف شده
  1. 20 11
      src/MoveGeneration.h
  2. 26 4
      src/UciParser.cpp
  3. 6 2
      src/UciParser.h
  4. 2 1
      src/main.cpp

+ 20 - 11
src/MoveGeneration.h

@@ -1,12 +1,12 @@
 #ifndef CHESSY_MOVEGENERATION_H
-#define CHESSY_MOVEGENERATION_H 
+#define CHESSY_MOVEGENERATION_H
 
 #include "BitBoard.h"
 
 namespace chessy
 {
     struct Move;
-    
+
     class PositionSet;
 
     class MoveGenerator;
@@ -17,6 +17,13 @@ struct chessy::Move
 {
     Index origin;
     Index destination;
+
+    Move(void)          = default;
+    Move(const Move&)   = default;
+    ~Move(void)         = default;
+
+    inline Move(Index origin, Index destination) :
+        origin{origin}, destination{destination} {}
 };
 
 
@@ -24,6 +31,7 @@ class chessy::PositionSet
 {
     Bitboard bitboard;
 
+public:
     struct PositionSetIterator
     {
         Bitboard bitboard;
@@ -32,11 +40,11 @@ class chessy::PositionSet
         {
             //if (bitboard == Bitboard(0)) return -1;
             return Bitboard::trailingZeroes(bitboard.bits);
-        } 
+        }
 
         inline void operator ++(void)
         {
-            // remove LSB
+            // remove least significant one-bit
             bitboard.bits &= bitboard.bits - 1;
         }
 
@@ -45,15 +53,14 @@ class chessy::PositionSet
             return bitboard != psi.bitboard;
         }
     };
-public:
-    
+
     inline PositionSetIterator begin(void) const
     {
-        return PositionSetIterator { bitboard };
+        return PositionSetIterator {bitboard};
     }
     inline PositionSetIterator end(void) const
     {
-        return PositionSetIterator { 0 };
+        return PositionSetIterator {0};
     }
 };
 
@@ -62,19 +69,21 @@ class chessy::MoveGenerator
 {
     struct MoveIterator
     {
+        PositionSet::PositionSetIterator pawnPushes;
         inline Move operator *(void) const
         {
-            // TODO: implement
+            Index pp = *pawnPushes;
+            return Move(pp - 8, pp);
         }
 
         inline void operator ++(void)
         {
-            // TODO: implement
+            ++pawnPushes;
         }
 
         inline bool operator !=(const MoveIterator& psi) const
         {
-            // TODO: implement
+            pawnPushes != PositionSet::PositionSetIterator {0};
         }
     };
 public:

+ 26 - 4
src/UciParser.cpp

@@ -1,5 +1,7 @@
 #include "UciParser.h"
 #include <string>
+#include <vector>
+#include <sstream>
 
 #include "ChessGame.h"
 
@@ -7,11 +9,31 @@ using namespace std;
 
 int UciParser::parse(istream& in, ostream& out)
 {
-    string line;
+    while (!is.eof()) {
+        string line;
+        getline(in, line);
+        executeLine(line);
+    }
+    return 0;
+}
+
+
+int UciParser::executeLine(const string& line)
+{
+    stringstream s {line};
+    string token;
+    string command;
+    vector<string> args;
+    s >> command;
+    while (s >> token) {
+        args.push_back(token);
+    }
+    executeCommand(command, args);
+}
 
-    getline(in, line);
 
-    out << "Thanks for the input: " << line;
+int UciParser::executeLine(const string& command,
+    const vector<string>& args)
+{
 
-    return 0;
 }

+ 6 - 2
src/UciParser.h

@@ -10,9 +10,13 @@ class UciParser
 {
 public:
     UciParser(void) = default;
-    ~UciParser(void) = default;
+    virtual ~UciParser(void) = default;
 
-    auto parse(std::istream& in, std::ostream& out) -> int;
+    virtual int parse(std::istream& in, std::ostream& out);
+
+    virtual int executeLine(const std::string& line);
+    virtual int executeCommand(const std::string& command,
+                               const std::vector<std::string>& args);
 };
 
 #endif // UCIPARSER_H

+ 2 - 1
src/main.cpp

@@ -5,6 +5,7 @@ using namespace std;
 
 auto main() -> int
 {
-    cout << "hello";
+    UciParser uciParser;
+    uciParser.parse(cin, cout);
     return 0;
 }