1 #include <Python.h> 2 3 #if PY_MAJOR_VERSION >= 3 4 #define PY3K 5 #endif 6 7 #include <string> 8 #include <map> 9 #include <vector> 10 #include <iostream> 11 #include <fstream> 12 #include <limits> 13 #include <algorithm> 14 #include <cmath> 15 16 #define ROWS_NBR 32 17 #define COLS_NBR 32 18 19 class AntSimulatorFast 20 { 21 public: 22 23 enum State {eStart='S', eEmpty='.', ePassed='x', 24 eFoodPiece='#', eEatenPiece='@', 25 eAntNorth='^', eAntEast='}', eAntSouth='v', eAntWest='{'}; 26 27 AntSimulatorFast(unsigned int inMaxMoves); 28 void parseMatrix(char* inFileStr); 29 30 void turnLeft(void); 31 void turnRight(void); 32 void moveForward(void); 33 34 void ifFoodAhead(PyObject* inIfTrue, PyObject* inIfFalse); 35 36 void run(PyObject* inWrappedFunc); 37 38 unsigned int mNbPiecesEaten; //!< Number of food pieces eaten. 39 40 private: 41 void reset(void); 42 43 std::vector< std::vector<char> > mOrigTrail; //!< Initial trail set-up. 44 unsigned int mMaxMoves; //!< Maximum number of moves allowed. 45 unsigned int mNbPiecesAvail; //!< Number of food pieces available. 46 unsigned int mRowStart; //!< Row at which the ant starts collecting food. 47 unsigned int mColStart; //!< Column at which the ant starts collecting food. 48 unsigned int mDirectionStart; //!< Direction at which the ant is looking when starting. 49 50 std::vector< std::vector<char> > mExecTrail; //!< Execution trail set-up. 51 unsigned int mNbMovesAnt; //!< Number of moves done by the ant. 52 unsigned int mRowAnt; //!< Row of the actual ant position. 53 unsigned int mColAnt; //!< Column of the actual ant position. 54 char mDirectionAnt; //!< Direction in which the ant is looking. 55 }; 56