From 9960b2fdf67dd5fafe9a4eed73ea09b8e788d2a9 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 30 Jun 2020 20:37:51 +0200 Subject: [PATCH 01/19] Ajout trace et empillement de sprite --- For Any Labyrinth Query U Execute.ipynb | 208 ++++++++++++++++++++++++ environment.yml | 12 +- include/laby/global_fr.hpp | 2 + include/laby/laby.hpp | 167 +++++++++++++++++-- include/laby/widget.hpp | 13 ++ laby-test.cpp | 18 +- share/laby/tiles/foot-e.svg | 31 ++++ share/laby/tiles/foot-n.svg | 31 ++++ share/laby/tiles/foot-s.svg | 31 ++++ share/laby/tiles/foot-w.svg | 33 ++++ solve.hpp | 206 +++++++++++++++++++++++ 11 files changed, 736 insertions(+), 16 deletions(-) create mode 100644 For Any Labyrinth Query U Execute.ipynb create mode 100644 share/laby/tiles/foot-e.svg create mode 100644 share/laby/tiles/foot-n.svg create mode 100644 share/laby/tiles/foot-s.svg create mode 100644 share/laby/tiles/foot-w.svg create mode 100644 solve.hpp diff --git a/For Any Labyrinth Query U Execute.ipynb b/For Any Labyrinth Query U Execute.ipynb new file mode 100644 index 0000000..d4877e4 --- /dev/null +++ b/For Any Labyrinth Query U Execute.ipynb @@ -0,0 +1,208 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# For Any Labyrinth Query U Execute\n", + "\n", + "**Author : Matthieu Robeyns**\n", + "\n", + "The following instructions explain how to solve any maze in the game Laby step by step.\n", + "If you have any information about the game Laby, please refer to this [page](https://github.com/sgimenez/laby/issues/52) first.\n", + "\n", + "Feel free to ask any questions [here](https://gitlab.u-psud.fr/ter-graphupsud/labycpp_python.git) !" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "skip" + } + }, + "source": [ + "### Introduction of our project:\n", + "\n", + "Before starting, you need to understand why do we do that and how it work.\n", + "
You are in a Jupyter Notebook, this platform unleash the power of execute any part of code you want by selected the cell and press Shift+Enter. But in this file, we shall you to execute cell step by step to avoid any error.\n", + "
The good point of Jupyter Notebook is, you can show the result of algorithm with dynamic's slides. To do that, you need to click on the button RISE Slideshow (to the left of a clock button). Once in the slide, you can scroll slide like any slider but some slides may get cell with code inside. And in RISE you can execute code without quit slideshow! You need to press Shift+Enter when you are in the cell and the output must appear (if it had one).\n", + "
After you run some cell you can run again the same cell while an error don't occur. \n", + "#### If a error occur when you re-run a cell, you need to restart the Kernel!\n", + "
To do that, click on the Kernel button (left to the Widgets button) and press 'Restart & Clear Output' then accept your choice and usually you can run the algorithm again without any error.\n", + "\n", + "\n", + "#### Notice : If you run RISE Slideshow, you do not see this part!\n", + "\n", + "First things you need to know is we are students in French University called [Université Paris-Saclay](https://www.universite-paris-saclay.fr/).\n", + "
This project is for 'Travaille d'Etude et de Recherche' (aka TER), aim to make us discover new horizon of program. This project promote team work, so I also works in graph representation in Jupyter Notebook with his colleague Damien Merret. Then for a better explanation of Jupyter and TER, please read [this](https://gitlab.u-psud.fr/ter-graphupsud/algorithme_des_plus-courts_chemins_en_cpp/blob/master/rapport.ipynb) first. \n", + "
Now I need to explain why did I choose this project for my research. First, Laby was the first program I use in my first degree. It was very effective to learn how use loops and language. So, I want to go further with Laby because when I finished the game, I was so sad cause interaction become limit when you know more about computer science.\n", + "\n", + "\n", + "This code was to experiment an heuristic about maze.\n", + "#### Heuristic: In maze, if you search an exit, keep the wall to your right when you walk.\n", + "\n", + "We use Laby's maze because Laby is very useful to resolve sample maze. Plus, Laby is a good first step to learn programming. Thus, even beginner can use our algorithm and see what append.\n", + "\n", + "Now, we need to talk more specially about the heuristic. Firstly, in Laby and maybe in lot of case we did not start with a wall to the left or to the right. So we need to find a wall. To do that, we just walk in front of us until we get the wall. Basically, we must see a wall, else if we just can find the exit.\n", + "So the first step of our algorithm is to find a wall with the function 'SearchWall()'.\n", + "\n", + "Then we just use a function called 'WallRight()', which check if a wall is in right of the ant and if it is true, when the ant can just walk away.\n", + "\n", + "But that not enough, cause Laby have one disrupt, in fact the maze have web and rock. Web can not be cross by the ant until he destroy it with a rock. Still ant can only leave one rock at once.\n", + "\n", + "So we need to adjust our code for those problem.\n", + "Hence, when we search a wall now and we see a web, we just bypass it (if it is possible), or we walk to the left now.\n", + "The second problem appear is the exit can be hide by a web, so to solve this problem we just save each position of rock and web we discover and when we can use a rock to destroy a web we backtracking, with the function 'Backtracking(Rock,WallToTheLeft)', and we explore the new way discovery by the web.\n", + "\n", + "By this method, we can solve all maze create in Laby, and maybe all maze we can generate.\n", + "All?? Unfortunately, that's not true.\n", + "Imagine a maze with a orphan wall in center. If the ant has this wall for reference, he just walk around indefinitely.\n", + "\n", + "Luckily, we have a solution. This solution need to implement a new mechanics in Laby, but that a small cost.\n", + "We need to create a new sprite which is the step of the ant. Thus, if the ant see his feet in the same direction he knows, he turn around and he decide to follow the wall in his left now.\n", + "\n", + "So, below you can train what we say with the code and each level of Laby.\n", + "\n", + "### What have you learn?\n", + "\n", + "The biggest mystery of all the time, how Laby works. This is very suprising to know Laby in Jupyter Notebook use lot of language to be very smooth. In fact, it use JavaScript and HTML to print the maze and the evolution of the ant. But for the action of the ant, we use C++. And to use this action in Jupyter Notebook... Unfortunately we need to use Python language, to be more specific about this part we need to talk about the Graph Project do by Damien Merret and Matthieu Robeyns. \n", + "\n", + "Have fun, and a nice day!" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Step 1\n", + "\n", + "Include [solve.hpp](https://gitlab.u-psud.fr/ter-graphupsud/labycpp_python/blob/master/solve.hpp).\n", + "\n", + "This header file contains everything necessary to solve and draw mazes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "#include \"solve.hpp\"\n", + "#include \n", + "#include \n", + "using namespace std;" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Step 2\n", + "\n", + "Run the code below to choose the maze you wish to solve. Simply fill in the box any of the following:\n", + "* 0\n", + "* 1a\n", + "* 1b\n", + "* 1c\n", + "* 2a\n", + "* 2b\n", + "* 2c\n", + "* 3a\n", + "* 3b\n", + "* 4a\n", + "* 4b\n", + "* counting-the-rocks\n", + "* this-is-crazy\n", + "\n", + "**Warning! If you want to try an another maze, you need to reboot the jupyter C++ kernel!**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": false, + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "string level;\n", + "cout << \"Enter the level you want to solve! \\nYou choose the level \";\n", + "cin >> level;\n", + " \n", + "LABY(level)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Step 3\n", + "\n", + "Now it's time to see the magic begin!\n", + "We just need to run the cell below, and basically your ant solve the maze!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "debut();\n", + "Walk();" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "celltoolbar": "Slideshow", + "kernelspec": { + "display_name": "C++17", + "language": "C++17", + "name": "xcpp17" + }, + "language_info": { + "codemirror_mode": "text/x-c++src", + "file_extension": ".cpp", + "mimetype": "text/x-c++src", + "name": "c++", + "version": "17" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/environment.yml b/environment.yml index 1e56b16..99f2a24 100644 --- a/environment.yml +++ b/environment.yml @@ -1,13 +1,19 @@ -# Software dependencies +# Logiciels requis pour utiliser et travailler sur les documents du cours Info 111 +#- "gitlab+https://gitlab.u-psud.fr/ter-graphupsud/labycpp_python/tree/master/ter-jupyter/Seance1" name: laby-jupyter channels: - conda-forge dependencies: -- notebook - xeus-cling +- notebook - xwidgets +- ipywidgets +- rise +- bqplot - pip +- jupyter_contrib_nbextensions - pip: - - . + - nbdime +# - . diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 7992763..81002a3 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -22,8 +22,10 @@ auto gauche() { return app -> gauche(); } auto pose() { return app -> pose(); } auto prend() { return app -> prend(); } auto seme() { return app -> sow(); } +auto trace() { return app -> sow_steps(); } auto ouvre() { return app -> ouvre(); } auto regarde() { return app -> regarde(); } +auto direction() { return app -> direct(); } bool a_gagne() { return app -> won(); } void LABY(std::string s) { diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 3f28b27..c8bdbab 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include // std::find #include "timer.hpp" const std::string LABY_FILE = __FILE__; @@ -14,10 +16,12 @@ const std::string LABY_BASENAME = "include/laby/laby.hpp"; const std::string LABY_PREFIX = LABY_FILE.substr(0, LABY_FILE.length()- LABY_BASENAME.length()); const std::string LABY_SHAREDIR = LABY_PREFIX+"share/laby/"; const std::string LABY_TILEDIR = LABY_SHAREDIR+"tiles/"; -const std::string LABY_LEVELDIR = LABY_SHAREDIR+"levels/"; +const std::string LABY_LEVELDIR = LABY_SHAREDIR+"levels"; bool use_inline_svg=true; std::vector svg_images; +bool moonwalk=true; + std::string utf8_substr(const std::string& str, unsigned int start, size_t leng) { if (leng==0) { return ""; } @@ -86,15 +90,18 @@ enum class Direction { North, West, South, East }; std::vector directions = { {-1,0}, {0,-1}, {1,0}, {0,1} }; enum Tile { - AntE, AntN, AntS, AntW, Exit, SmallRock, SmallWeb, Rock, Void, Wall, Web, Outside, RandomRock, RandomWeb + AntE, AntN, AntS, AntW, Exit, SmallRock, SmallWeb, Rock, Void, Wall, Web, Outside, RandomRock, RandomWeb, + FootN,FootS,FootE,FootW }; // Assumption: fake tiles are rendered as void std::vector tilenames = { "ant-e", "ant-n", "ant-s", "ant-w", "exit", "nrock", "nweb", "rock", "void", "wall", "web", "void", "void", "void" + ,"foot-n","foot-s","foot-e","foot-w" }; std::vector tilechars = { - u8"→", u8"↑", u8"↓", u8"←", "x", "ŕ", "ẃ", "r", ".", "o", "w", " ", "R", "W" + u8"→", u8"↑", u8"↓", u8"←", "x", "ŕ", "ẃ", "r", ".", "o", "w", " ", "R", "W","N","S","E","W" + }; enum PlayDirection { Forward, Backward, None }; @@ -159,12 +166,12 @@ class Board : public std::vector> { class Labyrinth { Board board; Position position; - Direction direction = Direction::North; + //Direction direction = Direction::North; Tile carry = Void; std::string message; bool _won = false; public: - + Direction direction = Direction::North; ////////////////////////////////////////////////////////////////////////// // Constructors Labyrinth() { @@ -235,14 +242,85 @@ class Labyrinth { s += "\n"; } return s; + } + + std::vector tiles_at_position(Position position) { + std::vector res = {}; + if( position.i < board.size() and + position.j < board[position.i].size()) { + // Quel tuile je vais afficher et dans quel ordre, c'est ici!! + + //res[0] est la tuile de fond + res.push_back(board.get(position)); + + //res[1] est pour la fourmi + std::vector::iterator direction_2 = std::find(ant_tiles.begin(), ant_tiles.end() ,board.get(position)); + if( direction_2 != ant_tiles.end()){ + res.push_back(ant_tiles[*direction_2]); + + //res[2] est pour le cailloux tenu par la fourmi. + if(carry == Tile::Rock){ + res.push_back(Tile::Rock); + } + } + } + return res; } - - std::string html() { + + std::string tiles_to_html(std::vector tiles) { + std::string s = ""; + + s += ""; + s += " "; + for(int i=tiles.size()-1; i>=0; i--) { + + if(i == 2){ + s += "
" ; + } + if(i == 1){ + //s += "
" ; /*svg_image(tiles[i])*/ + } + if(i == 0 && tiles[i]!=Tile::Void){ + s += " " + svg_image(tiles[i]) + " " ; + } + } + s += " \n"; + return s; + } + + std::string html(){ + board[position.i][position.j] = ant_tiles[int(direction)]; std::string s = "\n"; + for(int i = 0 ; i < board.size() ; i++) { + s += " \n"; + for(int j = 0 ; j < board[i].size() ; j++) { + s += tiles_to_html(tiles_at_position(Position(i,j))); + } + s += " \n"; + } + s+="
\n"; + s+="
";
+        if ( message.empty() )
+            s += " ";
+        s += message;
+        s += "
\n"; + return s; + } + + /** + std::string html() { + std::string s = "\n"; for ( auto line: view() ) { s += " \n"; for (int j=0; j\n"; + if( carry == Tile::Rock && (line[j]==Tile::AntE || line[j]==Tile::AntN || line[j]==Tile::AntS || line[j]==Tile::AntW) ){ + s += ""; + s += " \n"; + } + else{ + s += " \n"; + } } s += " \n"; } @@ -255,7 +333,8 @@ class Labyrinth { s += message; s += "\n"; return s; - } + } + */ Board view() { Board view = board; @@ -372,10 +451,17 @@ class Labyrinth { message = ""; return tile; } + + Direction direct(){ + Direction result=Direction(direction); + message=""; + return result; + } bool prend() { if ( carry == Tile::Void and regarde() == Tile::Rock ) { carry = Tile::Rock; + //board.set(position, Tile::Carry) board.set(devant(), Tile::Void); message = ""; return true; @@ -389,7 +475,11 @@ class Labyrinth { (regarde() == Tile::Void or regarde() == Tile::Web or regarde() == Tile::SmallWeb or - regarde() == Tile::SmallRock)) { + regarde() == Tile::SmallRock or + regarde() == Tile::FootN or + regarde() == Tile::FootE or + regarde() == Tile::FootS or + regarde() == Tile::FootW )) { carry = Tile::Void; board.set(devant(), Tile::Rock); message = ""; @@ -398,7 +488,32 @@ class Labyrinth { message = "Je ne peux pas poser."; return false; } - + + bool sow_steps(){ + if(moonwalk){ + switch(direction) { + case Direction::North: return sow(Tile::FootN); break; + case Direction::East: return sow(Tile::FootE); break; + case Direction::South: return sow(Tile::FootS); break; + case Direction::West: return sow(Tile::FootW); break; + default : return false; + } + } + else{return sow(Tile::Void);} + return true; + } + + bool sow(Tile feet){ + Tile tile = board.get(position); + if ( tile == Tile::Exit ) { + message = ""; + return false; + } + board.set(position, feet); + return true; + } + + bool sow() { Tile tile = board.get(position); if ( tile == Tile::Web or @@ -448,6 +563,7 @@ class Player { LabyrinthView &view; public: // for debuging Labyrinth original_value; + Labyrinth present_value; std::vector history; int time; @@ -469,6 +585,7 @@ class Player { Player(LabyrinthView &_view): view(_view), original_value(view.value), + present_value(view.value), play_direction(PlayDirection::Forward), play_fps(1), timer(std::bind(&Player::tick, this), play_fps) { @@ -491,7 +608,7 @@ class Player { void set_value(Labyrinth value) { if ( history.size() > 10000 ) - throw std::runtime_error("Votre programme a pris plus de 1000 étapes"); + throw std::runtime_error("Votre programme a pris plus de 10000 étapes"); history.push_back(value); if (not timer.running() and time == history.size() - 2 ) { time++; @@ -523,6 +640,20 @@ class Player { time = history.size() - 1; update(); } + + void hide_step() { + present_value = view.value; + if(moonwalk){moonwalk=false;} + else{moonwalk=true;} + auto randomized = present_value; + randomized.randomize(); + history[time] = randomized; + //svg_image[]= + update(); + std::cout << moonwalk << std::endl; + play_direction = PlayDirection::Forward; + timer.set_fps(play_fps); + } void step_backward() { if ( time > 0 ) { @@ -611,6 +742,18 @@ class LabyBaseApp { player.set_value(value); return res; } + + auto sow_steps(){ + auto value = player.get_value(); + auto res = value.sow_steps(); + player.set_value(value); + return res; + } + + auto direct() { + return player.get_value().direct(); + } + auto regarde() { return player.get_value().regarde(); } diff --git a/include/laby/widget.hpp b/include/laby/widget.hpp index 7874ab0..b0a9351 100644 --- a/include/laby/widget.hpp +++ b/include/laby/widget.hpp @@ -133,6 +133,19 @@ class PlayerView { // auto frame = xw::label(); // frame.value = ""; // widget.add(std::move(frame)); + + /** + auto step_label = xw::label(); + step_label.value = "Trace: "; + */ + auto step_box = button_template; + step_box.tooltip = "Hide Step"; + step_box.icon = "box"; + step_box.on_click([&player]() { player.hide_step(); }); + widget.add(std::move(step_box)); + //step_box. + + auto speed_label = xw::label(); speed_label.value = "Speed: "; diff --git a/laby-test.cpp b/laby-test.cpp index ee177ca..3f6c683 100644 --- a/laby-test.cpp +++ b/laby-test.cpp @@ -9,7 +9,7 @@ const string s = u8"o . . . . . o\n" u8"o . . . . . o\n" u8"o . ↑ . . . o\n" - u8"o o o o o o o\n"; + u8"o o o o o o o\n"; void testSvgImage() { svg_image(Tile::Exit); @@ -149,6 +149,22 @@ void testLabyrinth() { u8"o . . . . . o\n" u8"o . . . . . o\n" u8"o o o o o o o\n"); + +} + + + +void testStack(){ + // Rendre le labyrinth minimal. + const string stack_test= u8" . → r ."; + + auto l_stack = Labyrinth(stack_test); + ASSERTEQ( l_stack.to_string(), + u8" . → ."); + //ASSERT(); + + // Tester les 3 fonctions utilisé dans laby.hpp + } void testSow() { diff --git a/share/laby/tiles/foot-e.svg b/share/laby/tiles/foot-e.svg new file mode 100644 index 0000000..ffa0561 --- /dev/null +++ b/share/laby/tiles/foot-e.svg @@ -0,0 +1,31 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/share/laby/tiles/foot-n.svg b/share/laby/tiles/foot-n.svg new file mode 100644 index 0000000..768aac9 --- /dev/null +++ b/share/laby/tiles/foot-n.svg @@ -0,0 +1,31 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/share/laby/tiles/foot-s.svg b/share/laby/tiles/foot-s.svg new file mode 100644 index 0000000..9fe55e7 --- /dev/null +++ b/share/laby/tiles/foot-s.svg @@ -0,0 +1,31 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/share/laby/tiles/foot-w.svg b/share/laby/tiles/foot-w.svg new file mode 100644 index 0000000..818e1a1 --- /dev/null +++ b/share/laby/tiles/foot-w.svg @@ -0,0 +1,33 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + diff --git a/solve.hpp b/solve.hpp new file mode 100644 index 0000000..db03138 --- /dev/null +++ b/solve.hpp @@ -0,0 +1,206 @@ +#include "include/laby/global_fr.hpp" + +//To know if we wear a rock. +bool contient=false; + +//Count the number of rock the ant can see without take it. +int cptrock=0; +bool rockbf=false; + +//Count the number of web the ant can see without erase it +int cptnet=0; +bool netbf=false; + +/**Count the ant's shift for set the rock. + Start at 1 cause we beggin with one shift in left before use the function SetRock(). +*/ +int setrock=1; + +//To avoid the problem 'function undefine'. +void BackTracking(bool rck, bool wallL); + +/**Show steps on the board and forward. + (NB: if we unactivate the steps widget, they still showed but only void case xD). +*/ +void Step(){ + trace(); + avance(); +} + +//Move the ant in 180 degree. +void Gauche2(){ + gauche(); + gauche(); +} + +//To know if the ant can set the rock. +bool TestWall(){ + return regarde()==Tile::Wall; +} + +//Rotate the ant while he see nothing to set the rock. +void SetRock(int &cpt,bool back){ + if(back){ + while(cpt!=0){ + droite(); + cpt--; + } + cpt=1; + } + else{ + while(TestWall()){ + gauche(); + cpt++; + } + } +} + +//Open the door and finish the Labyrinth. Plus, set the rock if the ant wear one. +void EndLaby(){ + if(contient){ + gauche(); + SetRock(setrock,false); + pose(); + contient=false; + SetRock(setrock,true); + trace(); + ouvre(); + } + else{trace();ouvre();} +} + +//Keep position of a rock. +void PosCaillou(){ + cptrock++; + rockbf=true; +} + +//keep position of a web. +void PosToile(){ + cptnet++; + netbf=true; +} + +//Let the ant wear a rock (if able). +void TakeRock(){ + if(contient==false){ + prend(); + contient=true; + if(netbf){ + Gauche2(); + BackTracking(true,true); + } + } + else{PosCaillou(); + gauche(); + SetRock(setrock,false); + pose(); + SetRock(setrock,true); + prend();} +} + +//Let the ant set a rock on a web (if able). +void BreakNet(){ + if(contient){ + pose(); + cptnet--; + if(cptnet==0){netbf=false;} + contient=false; + /*if(rockbf){ + Gauche2(); + BackTracking(false,true); + }*/ + } + else{ + PosToile(); + gauche(); + } +} + +//Let the ant find a wall when the game start. +void SearchWall(){ + bool test=true; + while(test){ + switch(regarde()){ + case Tile::Wall : gauche(); test=false; break; + case Tile::Rock : TakeRock(); break; + case Tile::Web : BreakNet(); break; + case Tile::Void : Step(); break; + case Tile::SmallRock : Step(); break; + case Tile::SmallWeb : Step(); break; + case Tile::Exit : EndLaby(); test=false; break; + default: break; + } + } +} + +//Check if the ant get a wall on the right (or the left if wall_left is True). +bool WallRight(bool rck, bool wall_left){ + switch(regarde()){ + case Tile::Rock : TakeRock(); + if(wall_left){ + if(rck){ + cptrock--; + if(cptrock==0){rockbf=false; break;} + Gauche2(); return false; break; + } + } + else{return true; break;} + + case Tile::Web : BreakNet(); + if(wall_left){ + if(rck==false){ + cptrock--; + if(cptrock==0){rockbf=false; break;} + Gauche2(); return false; break; + } + } + else{return true; break;} + + case Tile::Exit : EndLaby(); return false; break; + + case Tile::Void : return true; break; + + case Tile::Wall : if(wall_left){droite();} + else{gauche();} + return true; break; + + case Tile::SmallRock : return true; break; + + case Tile::SmallWeb : return true; break; + + case Tile::FootN : if(direction()==Direction::North){Gauche2();return true; break;}else{return true; break;} + + case Tile::FootS : if(direction()==Direction::South){Gauche2();return true; break;}else{return true; break;} + + case Tile::FootE : if(direction()==Direction::East){Gauche2();return true; break;}else{return true; break;} + + case Tile::FootW : if(direction()==Direction::West){Gauche2();return true; break;}else{return true; break;} + + default : return false; + } + return false; +} + +//Let the ant do his backtracking. +void BackTracking(bool rck,bool wallL){ + while(WallRight(rck,wallL)){ + if(WallRight(rck,wallL)){ + Step(); + gauche(); + } + } +} + +//The Main Code! +void Walk(){ + SearchWall(); + droite(); + while(WallRight(false,false)){ + if(WallRight(false,false)){ + Step(); + droite(); + } + else{return 0;} + } +} From 13f19b51c951fa0b16e9253efd3bf9e0cbb54804 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 30 Jun 2020 22:11:12 +0200 Subject: [PATCH 02/19] Ajout de test --- laby-test.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/laby-test.cpp b/laby-test.cpp index 3f6c683..5993480 100644 --- a/laby-test.cpp +++ b/laby-test.cpp @@ -156,12 +156,23 @@ void testLabyrinth() { void testStack(){ // Rendre le labyrinth minimal. - const string stack_test= u8" . → r ."; + const string stack_test= u8"o . → r . x"; auto l_stack = Labyrinth(stack_test); ASSERTEQ( l_stack.to_string(), - u8" . → ."); - //ASSERT(); + u8"o . → r . x"); + ASSERTEQ(l.html(), R"html(
" ; + s += " "+svg_image(line[j])+"
"+svg_image(line[j])+"
+ + + + + + + + +
+
 
+)html"); // Tester les 3 fonctions utilisé dans laby.hpp From 7385bdf714e9052f99890564f47d639444446c21 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 30 Jun 2020 22:29:11 +0200 Subject: [PATCH 03/19] Ajout de test --- laby-test.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/laby-test.cpp b/laby-test.cpp index 5993480..f4e814e 100644 --- a/laby-test.cpp +++ b/laby-test.cpp @@ -173,9 +173,117 @@ void testStack(){
 
)html"); - - // Tester les 3 fonctions utilisé dans laby.hpp - + ASSERT(not l.avance()); + ASSERT( l.prend()); + ASSERTEQ(l.html(), R"html( + + + + + + + + +
+
+

+)html");
+    ASSERT( l.avance());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+                
+        
+        
+    
+
+
+

+)html");
+    ASSERT( l.avance());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+        
+                        
+        
+    
+
+
+

+)html");
+    ASSERT( l.gauche());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+        
+                        
+        
+    
+
+
+

+)html");
+    ASSERT( l.gauche());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+        
+                        
+        
+    
+
+
+

+)html");
+    ASSERT( l.pose());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+        
+                        
+        
+    
+
+

+)html");
+    ASSERT( l.gauche());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+        
+                        
+        
+    
+
+

+)html");
+    ASSERT( l.gauche());
+    ASSERTEQ(l.html(), R"html(
+    
+        
+        
+        
+        
+                        
+        
+    
+
+

+)html");
+    ASSERT( l.ouvre());    
 }
 
 void testSow() {
@@ -431,6 +539,7 @@ int main() {
     testFilename();
     testViewAt();
     testLabyrinth();
+    testStack();
     testSow();
     testLabyrinthValueSemantic();
     testLabyApp();

From b60c5686274b6617ce8bfc6ac4f3ce3cadea011c Mon Sep 17 00:00:00 2001
From: Matthieu 
Date: Tue, 30 Jun 2020 23:02:41 +0200
Subject: [PATCH 04/19] Fin de test

---
 For Any Labyrinth Query U Execute.ipynb | 31 +++++++++++++++++++++----
 include/laby/laby.hpp                   |  2 +-
 laby-test.cpp                           | 10 ++++----
 3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/For Any Labyrinth Query U Execute.ipynb b/For Any Labyrinth Query U Execute.ipynb
index d4877e4..0e3e79b 100644
--- a/For Any Labyrinth Query U Execute.ipynb	
+++ b/For Any Labyrinth Query U Execute.ipynb	
@@ -92,7 +92,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 1,
    "metadata": {
     "slideshow": {
      "slide_type": "fragment"
@@ -136,14 +136,37 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 2,
    "metadata": {
     "scrolled": false,
     "slideshow": {
      "slide_type": "fragment"
     }
    },
-   "outputs": [],
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Enter the level you want to solve! \n",
+      "You choose the level this-is-crazy\n"
+     ]
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "e19b3b0d45f447108ba23def6506ad37",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "A Jupyter widget"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
    "source": [
     "string level;\n",
     "cout << \"Enter the level you want to solve! \\nYou choose the level \";\n",
@@ -168,7 +191,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": null,
+   "execution_count": 3,
    "metadata": {
     "slideshow": {
      "slide_type": "fragment"
diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp
index c8bdbab..3710bba 100644
--- a/include/laby/laby.hpp
+++ b/include/laby/laby.hpp
@@ -275,7 +275,7 @@ class Labyrinth {
         for(int i=tiles.size()-1; i>=0; i--) {
                     
             if(i == 2){    
-                s += "
" ; + s += "
" ; } if(i == 1){ //s += "
" ; /*svg_image(tiles[i])*/ diff --git a/laby-test.cpp b/laby-test.cpp index f4e814e..65c8901 100644 --- a/laby-test.cpp +++ b/laby-test.cpp @@ -179,7 +179,7 @@ void testStack(){ -
+
@@ -194,7 +194,7 @@ void testStack(){ -
+
@@ -209,7 +209,7 @@ void testStack(){ -
+
@@ -223,7 +223,7 @@ void testStack(){ -
+
@@ -237,7 +237,7 @@ void testStack(){ -
+
From fa59d7aeefc6ea66ae406e2512b96106c15d24c6 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 3 Jul 2020 14:32:01 +0200 Subject: [PATCH 05/19] Ajout trace de pas --- For Any Labyrinth Query U Execute.ipynb | 8 +- environment.yml | 12 +-- include/laby/laby.hpp | 76 +------------ laby-test.cpp | 138 +----------------------- notebooks/this-is-crazy.ipynb | 6 +- 5 files changed, 13 insertions(+), 227 deletions(-) diff --git a/For Any Labyrinth Query U Execute.ipynb b/For Any Labyrinth Query U Execute.ipynb index 0e3e79b..7ea6879 100644 --- a/For Any Labyrinth Query U Execute.ipynb +++ b/For Any Labyrinth Query U Execute.ipynb @@ -92,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "slideshow": { "slide_type": "fragment" @@ -136,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "scrolled": false, "slideshow": { @@ -155,7 +155,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e19b3b0d45f447108ba23def6506ad37", + "model_id": "97ae5f2d244243aa8c88ab4500e98712", "version_major": 2, "version_minor": 0 }, @@ -191,7 +191,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "slideshow": { "slide_type": "fragment" diff --git a/environment.yml b/environment.yml index 99f2a24..1e56b16 100644 --- a/environment.yml +++ b/environment.yml @@ -1,19 +1,13 @@ -# Logiciels requis pour utiliser et travailler sur les documents du cours Info 111 -#- "gitlab+https://gitlab.u-psud.fr/ter-graphupsud/labycpp_python/tree/master/ter-jupyter/Seance1" +# Software dependencies name: laby-jupyter channels: - conda-forge dependencies: -- xeus-cling - notebook +- xeus-cling - xwidgets -- ipywidgets -- rise -- bqplot - pip -- jupyter_contrib_nbextensions - pip: - - nbdime -# - . + - . diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 3710bba..89d0542 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -244,83 +244,12 @@ class Labyrinth { return s; } - std::vector tiles_at_position(Position position) { - std::vector res = {}; - if( position.i < board.size() and - position.j < board[position.i].size()) { - // Quel tuile je vais afficher et dans quel ordre, c'est ici!! - - //res[0] est la tuile de fond - res.push_back(board.get(position)); - - //res[1] est pour la fourmi - std::vector::iterator direction_2 = std::find(ant_tiles.begin(), ant_tiles.end() ,board.get(position)); - if( direction_2 != ant_tiles.end()){ - res.push_back(ant_tiles[*direction_2]); - - //res[2] est pour le cailloux tenu par la fourmi. - if(carry == Tile::Rock){ - res.push_back(Tile::Rock); - } - } - } - return res; - } - - std::string tiles_to_html(std::vector tiles) { - std::string s = ""; - - s += ""; - s += " "; - for(int i=tiles.size()-1; i>=0; i--) { - - if(i == 2){ - s += "
" ; - } - if(i == 1){ - //s += "
" ; /*svg_image(tiles[i])*/ - } - if(i == 0 && tiles[i]!=Tile::Void){ - s += " " + svg_image(tiles[i]) + " " ; - } - } - s += " \n"; - return s; - } - - std::string html(){ - board[position.i][position.j] = ant_tiles[int(direction)]; - std::string s = "\n"; - for(int i = 0 ; i < board.size() ; i++) { - s += " \n"; - for(int j = 0 ; j < board[i].size() ; j++) { - s += tiles_to_html(tiles_at_position(Position(i,j))); - } - s += " \n"; - } - s+="
\n"; - s+="
";
-        if ( message.empty() )
-            s += " ";
-        s += message;
-        s += "
\n"; - return s; - } - - /** std::string html() { std::string s = "\n"; for ( auto line: view() ) { s += " \n"; for (int j=0; j\n"; - } - else{ - s += " \n"; - } + s += " \n"; } s += " \n"; } @@ -333,8 +262,7 @@ class Labyrinth { s += message; s += "\n"; return s; - } - */ + } Board view() { Board view = board; diff --git a/laby-test.cpp b/laby-test.cpp index 65c8901..ee177ca 100644 --- a/laby-test.cpp +++ b/laby-test.cpp @@ -9,7 +9,7 @@ const string s = u8"o . . . . . o\n" u8"o . . . . . o\n" u8"o . ↑ . . . o\n" - u8"o o o o o o o\n"; + u8"o o o o o o o\n"; void testSvgImage() { svg_image(Tile::Exit); @@ -149,141 +149,6 @@ void testLabyrinth() { u8"o . . . . . o\n" u8"o . . . . . o\n" u8"o o o o o o o\n"); - -} - - - -void testStack(){ - // Rendre le labyrinth minimal. - const string stack_test= u8"o . → r . x"; - - auto l_stack = Labyrinth(stack_test); - ASSERTEQ( l_stack.to_string(), - u8"o . → r . x"); - ASSERTEQ(l.html(), R"html(
"+svg_image(line[j])+""+svg_image(line[j])+"
- - - - - - - - -
-
 
-)html"); - ASSERT(not l.avance()); - ASSERT( l.prend()); - ASSERTEQ(l.html(), R"html( - - - - - - - - -
-
-

-)html");
-    ASSERT( l.avance());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-                
-        
-        
-    
-
-
-

-)html");
-    ASSERT( l.avance());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-        
-                        
-        
-    
-
-
-

-)html");
-    ASSERT( l.gauche());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-        
-                        
-        
-    
-
-
-

-)html");
-    ASSERT( l.gauche());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-        
-                        
-        
-    
-
-
-

-)html");
-    ASSERT( l.pose());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-        
-                        
-        
-    
-
-

-)html");
-    ASSERT( l.gauche());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-        
-                        
-        
-    
-
-

-)html");
-    ASSERT( l.gauche());
-    ASSERTEQ(l.html(), R"html(
-    
-        
-        
-        
-        
-                        
-        
-    
-
-

-)html");
-    ASSERT( l.ouvre());    
 }
 
 void testSow() {
@@ -539,7 +404,6 @@ int main() {
     testFilename();
     testViewAt();
     testLabyrinth();
-    testStack();
     testSow();
     testLabyrinthValueSemantic();
     testLabyApp();
diff --git a/notebooks/this-is-crazy.ipynb b/notebooks/this-is-crazy.ipynb
index 171f9fe..27cdd0a 100644
--- a/notebooks/this-is-crazy.ipynb
+++ b/notebooks/this-is-crazy.ipynb
@@ -11,13 +11,13 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": 9,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "1162d54a8f614cc5b5eb8fa37fe2dc07",
+       "model_id": "9647d9323736437796c7ec5526dd1eac",
        "version_major": 2,
        "version_minor": 0
       },
@@ -53,7 +53,7 @@
    "file_extension": ".cpp",
    "mimetype": "text/x-c++src",
    "name": "c++",
-   "version": "-std=c++17"
+   "version": "17"
   }
  },
  "nbformat": 4,

From 6a2d86affd0a3a5688f768b68751d15729cee253 Mon Sep 17 00:00:00 2001
From: Matthieu 
Date: Wed, 15 Jul 2020 11:56:32 +0200
Subject: [PATCH 06/19] remise du bon dossier

---
 For Any Labyrinth Query U Execute.ipynb | 31 ++++---------------------
 README.md                               |  2 +-
 2 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/For Any Labyrinth Query U Execute.ipynb b/For Any Labyrinth Query U Execute.ipynb
index 7ea6879..d4877e4 100644
--- a/For Any Labyrinth Query U Execute.ipynb	
+++ b/For Any Labyrinth Query U Execute.ipynb	
@@ -92,7 +92,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": null,
    "metadata": {
     "slideshow": {
      "slide_type": "fragment"
@@ -136,37 +136,14 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": null,
    "metadata": {
     "scrolled": false,
     "slideshow": {
      "slide_type": "fragment"
     }
    },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "Enter the level you want to solve! \n",
-      "You choose the level this-is-crazy\n"
-     ]
-    },
-    {
-     "data": {
-      "application/vnd.jupyter.widget-view+json": {
-       "model_id": "97ae5f2d244243aa8c88ab4500e98712",
-       "version_major": 2,
-       "version_minor": 0
-      },
-      "text/plain": [
-       "A Jupyter widget"
-      ]
-     },
-     "metadata": {},
-     "output_type": "display_data"
-    }
-   ],
+   "outputs": [],
    "source": [
     "string level;\n",
     "cout << \"Enter the level you want to solve! \\nYou choose the level \";\n",
@@ -191,7 +168,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": null,
    "metadata": {
     "slideshow": {
      "slide_type": "fragment"
diff --git a/README.md b/README.md
index f8934e2..9c7e0d4 100644
--- a/README.md
+++ b/README.md
@@ -43,4 +43,4 @@ Run:
     make tests
 
 Again, this is primitive, assuming g++ and xwidgets and stuff directly
-in the standard include path, or $(CONDA_PREFIX)/include.
+in the standard include path, or $(CONDA_PREFIX)/include.    

From a1315111aba6fba6a5108ee5e0e4e33d07800d93 Mon Sep 17 00:00:00 2001
From: Matthieu 
Date: Wed, 22 Jul 2020 09:46:10 +0200
Subject: [PATCH 07/19] =?UTF-8?q?modif=20conseill=C3=A9=20par=20le=20pull?=
 =?UTF-8?q?=20request?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 For Any Labyrinth Query U Execute.ipynb | 208 ------------------------
 README.md                               |   2 +-
 include/laby/global_fr.hpp              |   1 -
 include/laby/laby.hpp                   |  45 ++---
 4 files changed, 17 insertions(+), 239 deletions(-)
 delete mode 100644 For Any Labyrinth Query U Execute.ipynb

diff --git a/For Any Labyrinth Query U Execute.ipynb b/For Any Labyrinth Query U Execute.ipynb
deleted file mode 100644
index d4877e4..0000000
--- a/For Any Labyrinth Query U Execute.ipynb	
+++ /dev/null
@@ -1,208 +0,0 @@
-{
- "cells": [
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "slideshow": {
-     "slide_type": "slide"
-    }
-   },
-   "source": [
-    "# For Any Labyrinth Query U Execute\n",
-    "\n",
-    "**Author : Matthieu Robeyns**\n",
-    "\n",
-    "The following instructions explain how to solve any maze in the game Laby step by step.\n",
-    "If you have any information about the game Laby, please refer to this [page](https://github.com/sgimenez/laby/issues/52) first.\n",
-    "\n",
-    "Feel free to ask any questions [here](https://gitlab.u-psud.fr/ter-graphupsud/labycpp_python.git) !"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {
-    "slideshow": {
-     "slide_type": "skip"
-    }
-   },
-   "source": [
-    "### Introduction of our project:\n",
-    "\n",
-    "Before starting, you need to understand why do we do that and how it work.\n",
-    "
You are in a Jupyter Notebook, this platform unleash the power of execute any part of code you want by selected the cell and press Shift+Enter. But in this file, we shall you to execute cell step by step to avoid any error.\n", - "
The good point of Jupyter Notebook is, you can show the result of algorithm with dynamic's slides. To do that, you need to click on the button RISE Slideshow (to the left of a clock button). Once in the slide, you can scroll slide like any slider but some slides may get cell with code inside. And in RISE you can execute code without quit slideshow! You need to press Shift+Enter when you are in the cell and the output must appear (if it had one).\n", - "
After you run some cell you can run again the same cell while an error don't occur. \n", - "#### If a error occur when you re-run a cell, you need to restart the Kernel!\n", - "
To do that, click on the Kernel button (left to the Widgets button) and press 'Restart & Clear Output' then accept your choice and usually you can run the algorithm again without any error.\n", - "\n", - "\n", - "#### Notice : If you run RISE Slideshow, you do not see this part!\n", - "\n", - "First things you need to know is we are students in French University called [Université Paris-Saclay](https://www.universite-paris-saclay.fr/).\n", - "
This project is for 'Travaille d'Etude et de Recherche' (aka TER), aim to make us discover new horizon of program. This project promote team work, so I also works in graph representation in Jupyter Notebook with his colleague Damien Merret. Then for a better explanation of Jupyter and TER, please read [this](https://gitlab.u-psud.fr/ter-graphupsud/algorithme_des_plus-courts_chemins_en_cpp/blob/master/rapport.ipynb) first. \n", - "
Now I need to explain why did I choose this project for my research. First, Laby was the first program I use in my first degree. It was very effective to learn how use loops and language. So, I want to go further with Laby because when I finished the game, I was so sad cause interaction become limit when you know more about computer science.\n", - "\n", - "\n", - "This code was to experiment an heuristic about maze.\n", - "#### Heuristic: In maze, if you search an exit, keep the wall to your right when you walk.\n", - "\n", - "We use Laby's maze because Laby is very useful to resolve sample maze. Plus, Laby is a good first step to learn programming. Thus, even beginner can use our algorithm and see what append.\n", - "\n", - "Now, we need to talk more specially about the heuristic. Firstly, in Laby and maybe in lot of case we did not start with a wall to the left or to the right. So we need to find a wall. To do that, we just walk in front of us until we get the wall. Basically, we must see a wall, else if we just can find the exit.\n", - "So the first step of our algorithm is to find a wall with the function 'SearchWall()'.\n", - "\n", - "Then we just use a function called 'WallRight()', which check if a wall is in right of the ant and if it is true, when the ant can just walk away.\n", - "\n", - "But that not enough, cause Laby have one disrupt, in fact the maze have web and rock. Web can not be cross by the ant until he destroy it with a rock. Still ant can only leave one rock at once.\n", - "\n", - "So we need to adjust our code for those problem.\n", - "Hence, when we search a wall now and we see a web, we just bypass it (if it is possible), or we walk to the left now.\n", - "The second problem appear is the exit can be hide by a web, so to solve this problem we just save each position of rock and web we discover and when we can use a rock to destroy a web we backtracking, with the function 'Backtracking(Rock,WallToTheLeft)', and we explore the new way discovery by the web.\n", - "\n", - "By this method, we can solve all maze create in Laby, and maybe all maze we can generate.\n", - "All?? Unfortunately, that's not true.\n", - "Imagine a maze with a orphan wall in center. If the ant has this wall for reference, he just walk around indefinitely.\n", - "\n", - "Luckily, we have a solution. This solution need to implement a new mechanics in Laby, but that a small cost.\n", - "We need to create a new sprite which is the step of the ant. Thus, if the ant see his feet in the same direction he knows, he turn around and he decide to follow the wall in his left now.\n", - "\n", - "So, below you can train what we say with the code and each level of Laby.\n", - "\n", - "### What have you learn?\n", - "\n", - "The biggest mystery of all the time, how Laby works. This is very suprising to know Laby in Jupyter Notebook use lot of language to be very smooth. In fact, it use JavaScript and HTML to print the maze and the evolution of the ant. But for the action of the ant, we use C++. And to use this action in Jupyter Notebook... Unfortunately we need to use Python language, to be more specific about this part we need to talk about the Graph Project do by Damien Merret and Matthieu Robeyns. \n", - "\n", - "Have fun, and a nice day!" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Step 1\n", - "\n", - "Include [solve.hpp](https://gitlab.u-psud.fr/ter-graphupsud/labycpp_python/blob/master/solve.hpp).\n", - "\n", - "This header file contains everything necessary to solve and draw mazes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "outputs": [], - "source": [ - "#include \"solve.hpp\"\n", - "#include \n", - "#include \n", - "using namespace std;" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Step 2\n", - "\n", - "Run the code below to choose the maze you wish to solve. Simply fill in the box any of the following:\n", - "* 0\n", - "* 1a\n", - "* 1b\n", - "* 1c\n", - "* 2a\n", - "* 2b\n", - "* 2c\n", - "* 3a\n", - "* 3b\n", - "* 4a\n", - "* 4b\n", - "* counting-the-rocks\n", - "* this-is-crazy\n", - "\n", - "**Warning! If you want to try an another maze, you need to reboot the jupyter C++ kernel!**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": false, - "slideshow": { - "slide_type": "fragment" - } - }, - "outputs": [], - "source": [ - "string level;\n", - "cout << \"Enter the level you want to solve! \\nYou choose the level \";\n", - "cin >> level;\n", - " \n", - "LABY(level)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Step 3\n", - "\n", - "Now it's time to see the magic begin!\n", - "We just need to run the cell below, and basically your ant solve the maze!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "slideshow": { - "slide_type": "fragment" - } - }, - "outputs": [], - "source": [ - "debut();\n", - "Walk();" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "celltoolbar": "Slideshow", - "kernelspec": { - "display_name": "C++17", - "language": "C++17", - "name": "xcpp17" - }, - "language_info": { - "codemirror_mode": "text/x-c++src", - "file_extension": ".cpp", - "mimetype": "text/x-c++src", - "name": "c++", - "version": "17" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/README.md b/README.md index 9c7e0d4..ac13854 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,4 @@ Run: make tests Again, this is primitive, assuming g++ and xwidgets and stuff directly -in the standard include path, or $(CONDA_PREFIX)/include. +in the standard include path, or $(CONDA_PREFIX)/include. \ No newline at end of file diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 81002a3..04d1bc6 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -25,7 +25,6 @@ auto seme() { return app -> sow(); } auto trace() { return app -> sow_steps(); } auto ouvre() { return app -> ouvre(); } auto regarde() { return app -> regarde(); } -auto direction() { return app -> direct(); } bool a_gagne() { return app -> won(); } void LABY(std::string s) { diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 89d0542..9529a06 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -7,8 +7,6 @@ #include #include #include -#include -#include // std::find #include "timer.hpp" const std::string LABY_FILE = __FILE__; @@ -16,11 +14,11 @@ const std::string LABY_BASENAME = "include/laby/laby.hpp"; const std::string LABY_PREFIX = LABY_FILE.substr(0, LABY_FILE.length()- LABY_BASENAME.length()); const std::string LABY_SHAREDIR = LABY_PREFIX+"share/laby/"; const std::string LABY_TILEDIR = LABY_SHAREDIR+"tiles/"; -const std::string LABY_LEVELDIR = LABY_SHAREDIR+"levels"; +const std::string LABY_LEVELDIR = LABY_SHAREDIR+"levels/"; bool use_inline_svg=true; std::vector svg_images; -bool moonwalk=true; + std::string utf8_substr(const std::string& str, unsigned int start, size_t leng) { @@ -166,12 +164,12 @@ class Board : public std::vector> { class Labyrinth { Board board; Position position; - //Direction direction = Direction::North; + Direction direction = Direction::North; Tile carry = Void; std::string message; bool _won = false; - public: - Direction direction = Direction::North; + public: + bool leave_steps=true; ////////////////////////////////////////////////////////////////////////// // Constructors Labyrinth() { @@ -242,14 +240,14 @@ class Labyrinth { s += "\n"; } return s; - } + } std::string html() { - std::string s = "\n"; + std::string s = "
\n"; for ( auto line: view() ) { s += " \n"; for (int j=0; j\n"; + s += " \n"; } s += " \n"; } @@ -380,16 +378,9 @@ class Labyrinth { return tile; } - Direction direct(){ - Direction result=Direction(direction); - message=""; - return result; - } - bool prend() { if ( carry == Tile::Void and regarde() == Tile::Rock ) { carry = Tile::Rock; - //board.set(position, Tile::Carry) board.set(devant(), Tile::Void); message = ""; return true; @@ -418,12 +409,12 @@ class Labyrinth { } bool sow_steps(){ - if(moonwalk){ + if(leave_steps){ switch(direction) { case Direction::North: return sow(Tile::FootN); break; - case Direction::East: return sow(Tile::FootE); break; + case Direction::East: return sow(Tile::FootE); break; case Direction::South: return sow(Tile::FootS); break; - case Direction::West: return sow(Tile::FootW); break; + case Direction::West: return sow(Tile::FootW); break; default : return false; } } @@ -536,7 +527,7 @@ class Player { void set_value(Labyrinth value) { if ( history.size() > 10000 ) - throw std::runtime_error("Votre programme a pris plus de 10000 étapes"); + throw std::runtime_error("Votre programme a pris plus de 1000 étapes"); history.push_back(value); if (not timer.running() and time == history.size() - 2 ) { time++; @@ -571,14 +562,14 @@ class Player { void hide_step() { present_value = view.value; - if(moonwalk){moonwalk=false;} - else{moonwalk=true;} + if(leave_steps){leave_steps=false;} + else{leave_steps=true;} auto randomized = present_value; randomized.randomize(); history[time] = randomized; //svg_image[]= update(); - std::cout << moonwalk << std::endl; + std::cout << leave_steps << std::endl; play_direction = PlayDirection::Forward; timer.set_fps(play_fps); } @@ -676,11 +667,7 @@ class LabyBaseApp { auto res = value.sow_steps(); player.set_value(value); return res; - } - - auto direct() { - return player.get_value().direct(); - } + } auto regarde() { return player.get_value().regarde(); From 9731bd74368da7d18c6c77a64778221f68497e02 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 22 Jul 2020 09:58:41 +0200 Subject: [PATCH 08/19] Maj Pull Request --- include/laby/laby.hpp | 5 +- include/laby/widget.hpp | 15 +-- notebooks/this-is-crazy.ipynb | 19 +--- solve.hpp | 206 ---------------------------------- 4 files changed, 4 insertions(+), 241 deletions(-) delete mode 100644 solve.hpp diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 9529a06..c4989ed 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -482,7 +482,6 @@ class Player { LabyrinthView &view; public: // for debuging Labyrinth original_value; - Labyrinth present_value; std::vector history; int time; @@ -504,7 +503,6 @@ class Player { Player(LabyrinthView &_view): view(_view), original_value(view.value), - present_value(view.value), play_direction(PlayDirection::Forward), play_fps(1), timer(std::bind(&Player::tick, this), play_fps) { @@ -562,8 +560,7 @@ class Player { void hide_step() { present_value = view.value; - if(leave_steps){leave_steps=false;} - else{leave_steps=true;} + leave_steps = not leave_steps; auto randomized = present_value; randomized.randomize(); history[time] = randomized; diff --git a/include/laby/widget.hpp b/include/laby/widget.hpp index b0a9351..adb12a0 100644 --- a/include/laby/widget.hpp +++ b/include/laby/widget.hpp @@ -132,20 +132,7 @@ class PlayerView { // auto frame = xw::label(); // frame.value = ""; - // widget.add(std::move(frame)); - - /** - auto step_label = xw::label(); - step_label.value = "Trace: "; - */ - auto step_box = button_template; - step_box.tooltip = "Hide Step"; - step_box.icon = "box"; - step_box.on_click([&player]() { player.hide_step(); }); - widget.add(std::move(step_box)); - //step_box. - - + // widget.add(std::move(frame)); auto speed_label = xw::label(); speed_label.value = "Speed: "; diff --git a/notebooks/this-is-crazy.ipynb b/notebooks/this-is-crazy.ipynb index 27cdd0a..fba2efd 100644 --- a/notebooks/this-is-crazy.ipynb +++ b/notebooks/this-is-crazy.ipynb @@ -11,24 +11,9 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "9647d9323736437796c7ec5526dd1eac", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "A Jupyter widget" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#include \n", "LABY(\"this-is-crazy\")" diff --git a/solve.hpp b/solve.hpp deleted file mode 100644 index db03138..0000000 --- a/solve.hpp +++ /dev/null @@ -1,206 +0,0 @@ -#include "include/laby/global_fr.hpp" - -//To know if we wear a rock. -bool contient=false; - -//Count the number of rock the ant can see without take it. -int cptrock=0; -bool rockbf=false; - -//Count the number of web the ant can see without erase it -int cptnet=0; -bool netbf=false; - -/**Count the ant's shift for set the rock. - Start at 1 cause we beggin with one shift in left before use the function SetRock(). -*/ -int setrock=1; - -//To avoid the problem 'function undefine'. -void BackTracking(bool rck, bool wallL); - -/**Show steps on the board and forward. - (NB: if we unactivate the steps widget, they still showed but only void case xD). -*/ -void Step(){ - trace(); - avance(); -} - -//Move the ant in 180 degree. -void Gauche2(){ - gauche(); - gauche(); -} - -//To know if the ant can set the rock. -bool TestWall(){ - return regarde()==Tile::Wall; -} - -//Rotate the ant while he see nothing to set the rock. -void SetRock(int &cpt,bool back){ - if(back){ - while(cpt!=0){ - droite(); - cpt--; - } - cpt=1; - } - else{ - while(TestWall()){ - gauche(); - cpt++; - } - } -} - -//Open the door and finish the Labyrinth. Plus, set the rock if the ant wear one. -void EndLaby(){ - if(contient){ - gauche(); - SetRock(setrock,false); - pose(); - contient=false; - SetRock(setrock,true); - trace(); - ouvre(); - } - else{trace();ouvre();} -} - -//Keep position of a rock. -void PosCaillou(){ - cptrock++; - rockbf=true; -} - -//keep position of a web. -void PosToile(){ - cptnet++; - netbf=true; -} - -//Let the ant wear a rock (if able). -void TakeRock(){ - if(contient==false){ - prend(); - contient=true; - if(netbf){ - Gauche2(); - BackTracking(true,true); - } - } - else{PosCaillou(); - gauche(); - SetRock(setrock,false); - pose(); - SetRock(setrock,true); - prend();} -} - -//Let the ant set a rock on a web (if able). -void BreakNet(){ - if(contient){ - pose(); - cptnet--; - if(cptnet==0){netbf=false;} - contient=false; - /*if(rockbf){ - Gauche2(); - BackTracking(false,true); - }*/ - } - else{ - PosToile(); - gauche(); - } -} - -//Let the ant find a wall when the game start. -void SearchWall(){ - bool test=true; - while(test){ - switch(regarde()){ - case Tile::Wall : gauche(); test=false; break; - case Tile::Rock : TakeRock(); break; - case Tile::Web : BreakNet(); break; - case Tile::Void : Step(); break; - case Tile::SmallRock : Step(); break; - case Tile::SmallWeb : Step(); break; - case Tile::Exit : EndLaby(); test=false; break; - default: break; - } - } -} - -//Check if the ant get a wall on the right (or the left if wall_left is True). -bool WallRight(bool rck, bool wall_left){ - switch(regarde()){ - case Tile::Rock : TakeRock(); - if(wall_left){ - if(rck){ - cptrock--; - if(cptrock==0){rockbf=false; break;} - Gauche2(); return false; break; - } - } - else{return true; break;} - - case Tile::Web : BreakNet(); - if(wall_left){ - if(rck==false){ - cptrock--; - if(cptrock==0){rockbf=false; break;} - Gauche2(); return false; break; - } - } - else{return true; break;} - - case Tile::Exit : EndLaby(); return false; break; - - case Tile::Void : return true; break; - - case Tile::Wall : if(wall_left){droite();} - else{gauche();} - return true; break; - - case Tile::SmallRock : return true; break; - - case Tile::SmallWeb : return true; break; - - case Tile::FootN : if(direction()==Direction::North){Gauche2();return true; break;}else{return true; break;} - - case Tile::FootS : if(direction()==Direction::South){Gauche2();return true; break;}else{return true; break;} - - case Tile::FootE : if(direction()==Direction::East){Gauche2();return true; break;}else{return true; break;} - - case Tile::FootW : if(direction()==Direction::West){Gauche2();return true; break;}else{return true; break;} - - default : return false; - } - return false; -} - -//Let the ant do his backtracking. -void BackTracking(bool rck,bool wallL){ - while(WallRight(rck,wallL)){ - if(WallRight(rck,wallL)){ - Step(); - gauche(); - } - } -} - -//The Main Code! -void Walk(){ - SearchWall(); - droite(); - while(WallRight(false,false)){ - if(WallRight(false,false)){ - Step(); - droite(); - } - else{return 0;} - } -} From 2de892f05dd27b842ba7bb74616e030415e60c73 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 22 Jul 2020 14:22:09 +0200 Subject: [PATCH 09/19] PR fini normalement --- include/laby/laby.hpp | 51 ++++++++++++++++++----------------- include/laby/widget.hpp | 2 +- notebooks/this-is-crazy.ipynb | 21 ++++++++++++--- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index c4989ed..3ff29fc 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -18,8 +18,6 @@ const std::string LABY_LEVELDIR = LABY_SHAREDIR+"levels/"; bool use_inline_svg=true; std::vector svg_images; - - std::string utf8_substr(const std::string& str, unsigned int start, size_t leng) { if (leng==0) { return ""; } @@ -168,7 +166,7 @@ class Labyrinth { Tile carry = Void; std::string message; bool _won = false; - public: + public: bool leave_steps=true; ////////////////////////////////////////////////////////////////////////// // Constructors @@ -377,7 +375,7 @@ class Labyrinth { message = ""; return tile; } - + bool prend() { if ( carry == Tile::Void and regarde() == Tile::Rock ) { carry = Tile::Rock; @@ -391,14 +389,8 @@ class Labyrinth { bool pose() { if ( carry == Tile::Rock and - (regarde() == Tile::Void or - regarde() == Tile::Web or - regarde() == Tile::SmallWeb or - regarde() == Tile::SmallRock or - regarde() == Tile::FootN or - regarde() == Tile::FootE or - regarde() == Tile::FootS or - regarde() == Tile::FootW )) { + (regarde() != Tile::Rock or + regarde() != Tile::Exit) ) { carry = Tile::Void; board.set(devant(), Tile::Rock); message = ""; @@ -407,8 +399,24 @@ class Labyrinth { message = "Je ne peux pas poser."; return false; } + + bool leavesteps(){ + if(leave_steps){ + leave_steps = not leave_steps; + switch(direction) { + case Direction::North: return sow(Tile::FootN); break; + case Direction::East: return sow(Tile::FootE); break; + case Direction::South: return sow(Tile::FootS); break; + case Direction::West: return sow(Tile::FootW); break; + default : return false; + } + } + else{return sow(Tile::Void);} + return true; + } - bool sow_steps(){ + bool leavesteps(bool flag){ + leave_steps = flag; if(leave_steps){ switch(direction) { case Direction::North: return sow(Tile::FootN); break; @@ -422,26 +430,19 @@ class Labyrinth { return true; } - bool sow(Tile feet){ - Tile tile = board.get(position); - if ( tile == Tile::Exit ) { + bool sow(Tile tile){ + Tile position_tile = board.get(position); + if ( position_tile == Tile::Exit ) { message = ""; return false; } - board.set(position, feet); + board.set(position, tile); return true; } bool sow() { - Tile tile = board.get(position); - if ( tile == Tile::Web or - tile == Tile::Exit ) { - message = "Je ne peux pas semer."; - return false; - } - board.set(position, Tile::SmallRock); - return true; + return sow(Tile::SmallRock); } bool ouvre() { diff --git a/include/laby/widget.hpp b/include/laby/widget.hpp index adb12a0..7874ab0 100644 --- a/include/laby/widget.hpp +++ b/include/laby/widget.hpp @@ -132,7 +132,7 @@ class PlayerView { // auto frame = xw::label(); // frame.value = ""; - // widget.add(std::move(frame)); + // widget.add(std::move(frame)); auto speed_label = xw::label(); speed_label.value = "Speed: "; diff --git a/notebooks/this-is-crazy.ipynb b/notebooks/this-is-crazy.ipynb index fba2efd..171f9fe 100644 --- a/notebooks/this-is-crazy.ipynb +++ b/notebooks/this-is-crazy.ipynb @@ -11,9 +11,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "1162d54a8f614cc5b5eb8fa37fe2dc07", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "A Jupyter widget" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#include \n", "LABY(\"this-is-crazy\")" @@ -38,7 +53,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "17" + "version": "-std=c++17" } }, "nbformat": 4, From eb0616a6474b2911bd0ec82f6907cf6452110026 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 22 Jul 2020 16:22:52 +0200 Subject: [PATCH 10/19] PR fini normalement 2 --- include/laby/global_fr.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 04d1bc6..8af05d6 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -22,7 +22,7 @@ auto gauche() { return app -> gauche(); } auto pose() { return app -> pose(); } auto prend() { return app -> prend(); } auto seme() { return app -> sow(); } -auto trace() { return app -> sow_steps(); } +auto trace() { return app -> leavesteps(); } auto ouvre() { return app -> ouvre(); } auto regarde() { return app -> regarde(); } bool a_gagne() { return app -> won(); } From a48d3b1d5227cca30b19c543598e46e791cdfcdb Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 22 Jul 2020 16:25:15 +0200 Subject: [PATCH 11/19] PR fini normalement 3 --- include/laby/global_fr.hpp | 2 +- include/laby/laby.hpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 8af05d6..06d9011 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -22,7 +22,7 @@ auto gauche() { return app -> gauche(); } auto pose() { return app -> pose(); } auto prend() { return app -> prend(); } auto seme() { return app -> sow(); } -auto trace() { return app -> leavesteps(); } +auto trace() { return app -> leave_steps(); } auto ouvre() { return app -> ouvre(); } auto regarde() { return app -> regarde(); } bool a_gagne() { return app -> won(); } diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 3ff29fc..dbc0c77 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -167,7 +167,7 @@ class Labyrinth { std::string message; bool _won = false; public: - bool leave_steps=true; + bool _leave_steps=true; ////////////////////////////////////////////////////////////////////////// // Constructors Labyrinth() { @@ -400,9 +400,9 @@ class Labyrinth { return false; } - bool leavesteps(){ - if(leave_steps){ - leave_steps = not leave_steps; + bool leave_steps(){ + if(_leave_steps){ + _leave_steps = not _leave_steps; switch(direction) { case Direction::North: return sow(Tile::FootN); break; case Direction::East: return sow(Tile::FootE); break; @@ -561,13 +561,13 @@ class Player { void hide_step() { present_value = view.value; - leave_steps = not leave_steps; + _leave_steps = not leave_steps; auto randomized = present_value; randomized.randomize(); history[time] = randomized; //svg_image[]= update(); - std::cout << leave_steps << std::endl; + std::cout << _leave_steps << std::endl; play_direction = PlayDirection::Forward; timer.set_fps(play_fps); } From a4c6e91508cf9fcb43a0d12ce4276dd0448b57e6 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 22 Jul 2020 16:51:51 +0200 Subject: [PATCH 12/19] PR fini normalement 4 --- include/laby/global_fr.hpp | 3 ++- include/laby/laby.hpp | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 06d9011..71eaa02 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -22,7 +22,8 @@ auto gauche() { return app -> gauche(); } auto pose() { return app -> pose(); } auto prend() { return app -> prend(); } auto seme() { return app -> sow(); } -auto trace() { return app -> leave_steps(); } +auto trace_de_pas() { return app -> footstep(); } +auto traces_de_pas() { return app -> footsteps(); } auto ouvre() { return app -> ouvre(); } auto regarde() { return app -> regarde(); } bool a_gagne() { return app -> won(); } diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index dbc0c77..1948890 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -362,6 +362,7 @@ class Labyrinth { tile_devant == Tile::Rock or tile_devant == Tile::Exit or tile_devant == Tile::Wall) { + //Rajouter le mode laisser une trace ici!! message = "Je ne peux pas avancer."; return false; } @@ -388,9 +389,9 @@ class Labyrinth { } bool pose() { - if ( carry == Tile::Rock and - (regarde() != Tile::Rock or - regarde() != Tile::Exit) ) { + if ( carry == Tile::Rock and not + (regarde() == Tile::Rock or + regarde() == Tile::Exit) ) { carry = Tile::Void; board.set(devant(), Tile::Rock); message = ""; @@ -401,8 +402,8 @@ class Labyrinth { } bool leave_steps(){ - if(_leave_steps){ - _leave_steps = not _leave_steps; + if(_footsteps){ + _footsteps = not _footsteps; switch(direction) { case Direction::North: return sow(Tile::FootN); break; case Direction::East: return sow(Tile::FootE); break; @@ -416,8 +417,8 @@ class Labyrinth { } bool leavesteps(bool flag){ - leave_steps = flag; - if(leave_steps){ + _footsteps = flag; + if(_footsteps){ switch(direction) { case Direction::North: return sow(Tile::FootN); break; case Direction::East: return sow(Tile::FootE); break; @@ -660,7 +661,7 @@ class LabyBaseApp { return res; } - auto sow_steps(){ + auto leave_steps(){ auto value = player.get_value(); auto res = value.sow_steps(); player.set_value(value); From 20b7769a36ad0806cc65590789d84e14af7cf30c Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 24 Aug 2020 10:54:42 +0200 Subject: [PATCH 13/19] =?UTF-8?q?fonction=20cr=C3=A9=C3=A9e=20mais=20pas?= =?UTF-8?q?=20reconnue...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/laby/global_fr.hpp | 24 ++++++++--------- include/laby/laby.hpp | 51 ++++++++++++++++++----------------- notebooks/2a.ipynb | 23 +++------------- notebooks/this-is-crazy.ipynb | 2 +- 4 files changed, 44 insertions(+), 56 deletions(-) diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 71eaa02..59c153d 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -15,18 +15,18 @@ auto PetiteToile = Tile::SmallWeb; auto Sortie = Tile::Exit; auto Mur = Tile::Wall; auto Vide = Tile::Void; -auto debut() { return app -> debut(); } -auto avance() { return app -> avance(); } -auto droite() { return app -> droite(); } -auto gauche() { return app -> gauche(); } -auto pose() { return app -> pose(); } -auto prend() { return app -> prend(); } -auto seme() { return app -> sow(); } -auto trace_de_pas() { return app -> footstep(); } -auto traces_de_pas() { return app -> footsteps(); } -auto ouvre() { return app -> ouvre(); } -auto regarde() { return app -> regarde(); } -bool a_gagne() { return app -> won(); } +auto debut() { return app -> debut(); } +auto avance() { return app -> avance(); } +auto droite() { return app -> droite(); } +auto gauche() { return app -> gauche(); } +auto pose() { return app -> pose(); } +auto prend() { return app -> prend(); } +auto seme() { return app -> sow(); } +auto trace_de_pas() { return app -> footstep(); } +auto traces_de_pas() { return app -> footsteps(bool flag); } +auto ouvre() { return app -> ouvre(); } +auto regarde() { return app -> regarde(); } +bool a_gagne() { return app -> won(); } void LABY(std::string s) { app = laby_level(s); diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index 1948890..a80c2ae 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -87,16 +87,16 @@ std::vector directions = { {-1,0}, {0,-1}, {1,0}, {0,1} }; enum Tile { AntE, AntN, AntS, AntW, Exit, SmallRock, SmallWeb, Rock, Void, Wall, Web, Outside, RandomRock, RandomWeb, - FootN,FootS,FootE,FootW + FootN, FootS, FootE, FootW }; // Assumption: fake tiles are rendered as void std::vector tilenames = { "ant-e", "ant-n", "ant-s", "ant-w", "exit", "nrock", "nweb", "rock", "void", "wall", "web", "void", "void", "void" - ,"foot-n","foot-s","foot-e","foot-w" + ,"foot-n", "foot-s", "foot-e", "foot-w" }; std::vector tilechars = { - u8"→", u8"↑", u8"↓", u8"←", "x", "ŕ", "ẃ", "r", ".", "o", "w", " ", "R", "W","N","S","E","W" + u8"→", u8"↑", u8"↓", u8"←", "x", "ŕ", "ẃ", "r", ".", "o", "w", " ", "R", "W", "N", "S", "E", "W" }; @@ -362,7 +362,6 @@ class Labyrinth { tile_devant == Tile::Rock or tile_devant == Tile::Exit or tile_devant == Tile::Wall) { - //Rajouter le mode laisser une trace ici!! message = "Je ne peux pas avancer."; return false; } @@ -391,7 +390,8 @@ class Labyrinth { bool pose() { if ( carry == Tile::Rock and not (regarde() == Tile::Rock or - regarde() == Tile::Exit) ) { + regarde() == Tile::Exit or + regarde() == Tile::Wall) ) { carry = Tile::Void; board.set(devant(), Tile::Rock); message = ""; @@ -401,24 +401,20 @@ class Labyrinth { return false; } - bool leave_steps(){ - if(_footsteps){ - _footsteps = not _footsteps; - switch(direction) { - case Direction::North: return sow(Tile::FootN); break; - case Direction::East: return sow(Tile::FootE); break; - case Direction::South: return sow(Tile::FootS); break; - case Direction::West: return sow(Tile::FootW); break; - default : return false; - } + bool footstep(){ + switch(direction) { + case Direction::North: return sow(Tile::FootN); break; + case Direction::East: return sow(Tile::FootE); break; + case Direction::South: return sow(Tile::FootS); break; + case Direction::West: return sow(Tile::FootW); break; + default : return false; } - else{return sow(Tile::Void);} return true; } - bool leavesteps(bool flag){ - _footsteps = flag; - if(_footsteps){ + bool footsteps(bool flag){ + _leave_steps = flag; + if(_leave_steps){ switch(direction) { case Direction::North: return sow(Tile::FootN); break; case Direction::East: return sow(Tile::FootE); break; @@ -560,13 +556,13 @@ class Player { update(); } - void hide_step() { + void erase_step() { + //Supprimer ce qu'il y a dans le tableau avec les trace de pas present_value = view.value; _leave_steps = not leave_steps; auto randomized = present_value; randomized.randomize(); - history[time] = randomized; - //svg_image[]= + history[time] = randomized; update(); std::cout << _leave_steps << std::endl; play_direction = PlayDirection::Forward; @@ -661,9 +657,16 @@ class LabyBaseApp { return res; } - auto leave_steps(){ + auto footstep(){ + auto value = player.get_value(); + auto res = value.footstep(); + player.set_value(value); + return res; + } + + auto footsteps(bool flag){ auto value = player.get_value(); - auto res = value.sow_steps(); + auto res = value.footsteps(bool flag); player.set_value(value); return res; } diff --git a/notebooks/2a.ipynb b/notebooks/2a.ipynb index 721a2a7..796a62d 100644 --- a/notebooks/2a.ipynb +++ b/notebooks/2a.ipynb @@ -13,24 +13,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "2be6724b1cdc413eaeeb8eaf41d7ed0d", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "A Jupyter widget" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#include \n", "LABY(\"2a\")" @@ -38,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -67,7 +52,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "-std=c++17" + "version": "17" } }, "nbformat": 4, diff --git a/notebooks/this-is-crazy.ipynb b/notebooks/this-is-crazy.ipynb index 171f9fe..3728745 100644 --- a/notebooks/this-is-crazy.ipynb +++ b/notebooks/this-is-crazy.ipynb @@ -53,7 +53,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "-std=c++17" + "version": "17" } }, "nbformat": 4, From d549f3e6bbc6241670e0c68dfb428cb265a19628 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 24 Aug 2020 11:12:52 +0200 Subject: [PATCH 14/19] global_fr correct --- include/laby/global_fr.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 59c153d..61130fc 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -15,18 +15,18 @@ auto PetiteToile = Tile::SmallWeb; auto Sortie = Tile::Exit; auto Mur = Tile::Wall; auto Vide = Tile::Void; -auto debut() { return app -> debut(); } -auto avance() { return app -> avance(); } -auto droite() { return app -> droite(); } -auto gauche() { return app -> gauche(); } -auto pose() { return app -> pose(); } -auto prend() { return app -> prend(); } -auto seme() { return app -> sow(); } -auto trace_de_pas() { return app -> footstep(); } -auto traces_de_pas() { return app -> footsteps(bool flag); } -auto ouvre() { return app -> ouvre(); } -auto regarde() { return app -> regarde(); } -bool a_gagne() { return app -> won(); } +auto debut() { return app -> debut(); } +auto avance() { return app -> avance(); } +auto droite() { return app -> droite(); } +auto gauche() { return app -> gauche(); } +auto pose() { return app -> pose(); } +auto prend() { return app -> prend(); } +auto seme() { return app -> sow(); } +auto trace_de_pas() { return app -> footstep(); } +auto traces_de_pas(bool flag) { return app -> footsteps(bool flag); } +auto ouvre() { return app -> ouvre(); } +auto regarde() { return app -> regarde(); } +bool a_gagne() { return app -> won(); } void LABY(std::string s) { app = laby_level(s); From baa10bc0a1ce3a070ff0ff6eae5240b66f7bf82c Mon Sep 17 00:00:00 2001 From: Disatiler <36360389+Disatiler@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:21:11 +0200 Subject: [PATCH 15/19] Update 2a.ipynb --- notebooks/2a.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/2a.ipynb b/notebooks/2a.ipynb index 796a62d..b9f628f 100644 --- a/notebooks/2a.ipynb +++ b/notebooks/2a.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ From fd6467fd8bc37ea559f6e352c7bed24424dd217c Mon Sep 17 00:00:00 2001 From: Disatiler <36360389+Disatiler@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:23:16 +0200 Subject: [PATCH 16/19] Update 2a.ipynb --- notebooks/2a.ipynb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/notebooks/2a.ipynb b/notebooks/2a.ipynb index b9f628f..9bf0f4c 100644 --- a/notebooks/2a.ipynb +++ b/notebooks/2a.ipynb @@ -15,7 +15,22 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "2be6724b1cdc413eaeeb8eaf41d7ed0d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "A Jupyter widget" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#include \n", "LABY(\"2a\")" @@ -23,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -52,7 +67,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "17" + "version": "-std=c++17" } }, "nbformat": 4, From b3e6a799067acda9cc9bc765e4519e9e1463f668 Mon Sep 17 00:00:00 2001 From: Disatiler <36360389+Disatiler@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:23:42 +0200 Subject: [PATCH 17/19] Update 2a.ipynb --- notebooks/2a.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/2a.ipynb b/notebooks/2a.ipynb index 9bf0f4c..721a2a7 100644 --- a/notebooks/2a.ipynb +++ b/notebooks/2a.ipynb @@ -16,7 +16,7 @@ "execution_count": 1, "metadata": {}, "outputs": [ - { + { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2be6724b1cdc413eaeeb8eaf41d7ed0d", From 5ddcaf94637e7e3008432202c1f0a0a10607ffbf Mon Sep 17 00:00:00 2001 From: Disatiler <36360389+Disatiler@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:24:11 +0200 Subject: [PATCH 18/19] Update this-is-crazy.ipynb --- notebooks/this-is-crazy.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/this-is-crazy.ipynb b/notebooks/this-is-crazy.ipynb index 3728745..171f9fe 100644 --- a/notebooks/this-is-crazy.ipynb +++ b/notebooks/this-is-crazy.ipynb @@ -53,7 +53,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "c++", - "version": "17" + "version": "-std=c++17" } }, "nbformat": 4, From 6523e32ca891251f84df88d05821bd503f35d466 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Wed, 26 Aug 2020 22:48:44 +0200 Subject: [PATCH 19/19] Fin Pr de trace de pas --- include/laby/global_fr.hpp | 2 +- include/laby/laby.hpp | 38 +++++++++++++----------------- laby.egg-info/PKG-INFO | 12 ++++++++++ laby.egg-info/SOURCES.txt | 38 ++++++++++++++++++++++++++++++ laby.egg-info/dependency_links.txt | 1 + laby.egg-info/top_level.txt | 1 + 6 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 laby.egg-info/PKG-INFO create mode 100644 laby.egg-info/SOURCES.txt create mode 100644 laby.egg-info/dependency_links.txt create mode 100644 laby.egg-info/top_level.txt diff --git a/include/laby/global_fr.hpp b/include/laby/global_fr.hpp index 61130fc..ca29009 100644 --- a/include/laby/global_fr.hpp +++ b/include/laby/global_fr.hpp @@ -23,7 +23,7 @@ auto pose() { return app -> pose(); } auto prend() { return app -> prend(); } auto seme() { return app -> sow(); } auto trace_de_pas() { return app -> footstep(); } -auto traces_de_pas(bool flag) { return app -> footsteps(bool flag); } +auto traces_de_pas(bool flag) { return app -> footsteps(flag); } auto ouvre() { return app -> ouvre(); } auto regarde() { return app -> regarde(); } bool a_gagne() { return app -> won(); } diff --git a/include/laby/laby.hpp b/include/laby/laby.hpp index a80c2ae..343573f 100644 --- a/include/laby/laby.hpp +++ b/include/laby/laby.hpp @@ -366,6 +366,9 @@ class Labyrinth { return false; } message = ""; + if(_leave_steps){ + footstep(); + } position = devant(); return true; } @@ -414,16 +417,6 @@ class Labyrinth { bool footsteps(bool flag){ _leave_steps = flag; - if(_leave_steps){ - switch(direction) { - case Direction::North: return sow(Tile::FootN); break; - case Direction::East: return sow(Tile::FootE); break; - case Direction::South: return sow(Tile::FootS); break; - case Direction::West: return sow(Tile::FootW); break; - default : return false; - } - } - else{return sow(Tile::Void);} return true; } @@ -556,17 +549,18 @@ class Player { update(); } - void erase_step() { - //Supprimer ce qu'il y a dans le tableau avec les trace de pas - present_value = view.value; - _leave_steps = not leave_steps; - auto randomized = present_value; - randomized.randomize(); - history[time] = randomized; - update(); - std::cout << _leave_steps << std::endl; - play_direction = PlayDirection::Forward; - timer.set_fps(play_fps); + void erase_footsteps() { + //Supprimer ce qu'il y a dans le tableau avec les trace de pas + //Double boucle pour vider + Board board = Board(); + for(int i = 0; i < board.size(); i++){ + for(int j = 0; j < board[i].size(); j++){ + if( board.get(Position(i,j)) == (Tile::FootN or Tile::FootS or Tile::FootE or Tile::FootW)){ + board.set(Position(i,j),Tile::Void); + } + } + } + update(); } void step_backward() { @@ -666,7 +660,7 @@ class LabyBaseApp { auto footsteps(bool flag){ auto value = player.get_value(); - auto res = value.footsteps(bool flag); + auto res = value.footsteps(flag); player.set_value(value); return res; } diff --git a/laby.egg-info/PKG-INFO b/laby.egg-info/PKG-INFO new file mode 100644 index 0000000..093e3c9 --- /dev/null +++ b/laby.egg-info/PKG-INFO @@ -0,0 +1,12 @@ +Metadata-Version: 1.1 +Name: laby +Version: 0.0.1 +Summary: Laby-Jupyter: Learn programming, playing with ants and spider webs ;-) In Jupyter :-) +Home-page: https://github.com/nthiery/laby-jupyter/ +Author: Nicolas M. Thiéry +Author-email: nthiery@users.sf.net +License: GPLv2+ +Description: UNKNOWN +Platform: UNKNOWN +Classifier: Development Status :: 3 - Alpha +Classifier: License :: OSI Approved :: GNU General Public License (GPL) diff --git a/laby.egg-info/SOURCES.txt b/laby.egg-info/SOURCES.txt new file mode 100644 index 0000000..e879412 --- /dev/null +++ b/laby.egg-info/SOURCES.txt @@ -0,0 +1,38 @@ +README.md +setup.py +include/laby/global_fr.hpp +include/laby/laby.hpp +include/laby/timer.hpp +include/laby/widget.hpp +laby.egg-info/PKG-INFO +laby.egg-info/SOURCES.txt +laby.egg-info/dependency_links.txt +laby.egg-info/top_level.txt +share/laby/levels/0.laby +share/laby/levels/1a.laby +share/laby/levels/1b.laby +share/laby/levels/1c.laby +share/laby/levels/2a.laby +share/laby/levels/2b.laby +share/laby/levels/2c.laby +share/laby/levels/3a.laby +share/laby/levels/3b.laby +share/laby/levels/4a.laby +share/laby/levels/4b.laby +share/laby/levels/counting-the-rocks.laby +share/laby/levels/this-is-crazy.laby +share/laby/tiles/ant-e.svg +share/laby/tiles/ant-n.svg +share/laby/tiles/ant-s.svg +share/laby/tiles/ant-w.svg +share/laby/tiles/exit.svg +share/laby/tiles/foot-e.svg +share/laby/tiles/foot-n.svg +share/laby/tiles/foot-s.svg +share/laby/tiles/foot-w.svg +share/laby/tiles/nrock.svg +share/laby/tiles/nweb.svg +share/laby/tiles/rock.svg +share/laby/tiles/void.svg +share/laby/tiles/wall.svg +share/laby/tiles/web.svg \ No newline at end of file diff --git a/laby.egg-info/dependency_links.txt b/laby.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/laby.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/laby.egg-info/top_level.txt b/laby.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/laby.egg-info/top_level.txt @@ -0,0 +1 @@ +
"+svg_image(line[j])+"