From e4260e7abdb7a7e5ff00f6dcb74e8cbfb6d0a03d Mon Sep 17 00:00:00 2001
From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr>
Date: Tue, 17 May 2016 19:02:50 +0200
Subject: [PATCH] Changed implementation for function move_penguin()

---
 AI/src/game/penguin.cpp | 47 +++++++++++++++++++++--------------------
 AI/src/game/penguin.hpp |  2 +-
 2 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/AI/src/game/penguin.cpp b/AI/src/game/penguin.cpp
index 180ab43..7e1a7e0 100644
--- a/AI/src/game/penguin.cpp
+++ b/AI/src/game/penguin.cpp
@@ -135,53 +135,56 @@ namespace game
 		return state.current_player_red ? state.nb_moves_red : state.nb_moves_blue;
 	}
 
-	void penguin::move_penguin(uint32_t* p)
+	/*
+		Moves the penguin p (modify its position value), making it do its rel_move move.
+		At the end of the function the penguin will be composed of just its new position (every other bit is at 0)
+	*/
+	void penguin::move_penguin(uint32_t* p, uint16_t rel_move)
 	{
-		uint8_t move_number = ((*p) >> 6) & 63; //Move number for the current penguin
 		uint32_t penguin_copy = (*p) >> 12;
 		//Direction A
-		if((penguin_copy & 7) > move_number)
+		if((penguin_copy & 7) > rel_move) //If the penguin total moves in this direction are greater than the move we want to do for it (not equal because moves start at 0)
 		{
 			//Move direction A
-			(*p) = (7 * (move_number +1)) + ((*p) & 63);
+			(*p) = (7 * (rel_move +1)) + ((*p) & 63);
 			return;
 		}
-		move_number -= penguin_copy & 7;
+		rel_move -= penguin_copy & 7;
 		penguin_copy = penguin_copy >> 3;
-		if((penguin_copy & 7) > move_number)
+		if((penguin_copy & 7) > rel_move)
 		{
 			//Move direction B
-			(*p) = (-1 * (move_number +1)) + ((*p) & 63);
+			(*p) = (-1 * (rel_move +1)) + ((*p) & 63);
 			return;
 		}
-		move_number -= penguin_copy & 7;
+		rel_move -= penguin_copy & 7;
 		penguin_copy = penguin_copy >> 3;
-		if((penguin_copy & 7) > move_number)
+		if((penguin_copy & 7) > rel_move)
 		{
 			//Move direction C
-			(*p) = (-8 * (move_number +1)) + ((*p) & 63);
+			(*p) = (-8 * (rel_move +1)) + ((*p) & 63);
 			return;
 		}
-		move_number -= penguin_copy & 7;
+		rel_move -= penguin_copy & 7;
 		penguin_copy = penguin_copy >> 3;
-		if((penguin_copy & 7) > move_number)
+		if((penguin_copy & 7) > rel_move)
 		{
 			//Move direction D
-			(*p) = (-7 * (move_number +1)) + ((*p) & 63);
+			(*p) = (-7 * (rel_move +1)) + ((*p) & 63);
 			return;
 		}
-		move_number -= penguin_copy & 7;
+		rel_move -= penguin_copy & 7;
 		penguin_copy = penguin_copy >> 3;
-		if((penguin_copy & 7) > move_number)
+		if((penguin_copy & 7) > rel_move)
 		{
 			//Move direction E
-			(*p) = (1 * (move_number +1)) + ((*p) & 63);
+			(*p) = (1 * (rel_move +1)) + ((*p) & 63);
 			return;
 		}
-		move_number -= penguin_copy & 7;
+		rel_move -= penguin_copy & 7;
 		penguin_copy = penguin_copy >> 3;
 		//Move direction F
-		(*p) = (8 * (move_number +1)) + ((*p) & 63);
+		(*p) = (8 * (rel_move +1)) + ((*p) & 63);
 	}
 
 	int penguin::update_moves(uint32_t* p, uint64_t obstacles)
@@ -308,13 +311,11 @@ namespace game
 				//We replace this tile with an empty one (0 in the bitboard)
 				state.one_fish = state.one_fish & ~(((uint64_t) 1) << POS(*peng));
 			}
-			/*
-			//TODO: implements methods with arrays
 
-			//Move the current penguin
-			move_penguin(p);
-			*/
+			// MOVE THE PENGUIN
+			move_penguin(peng, rel_move);
 		}
+		// END CAN_WE PLAY. We will now compute the moves for every penguin and for the player.
 
 		//Update moves on all penguins of the next player
 		uint64_t obstacles = (~(state.one_fish | state.two_fish | state.three_fish));
diff --git a/AI/src/game/penguin.hpp b/AI/src/game/penguin.hpp
index 1ec2fec..c8aa7a7 100644
--- a/AI/src/game/penguin.hpp
+++ b/AI/src/game/penguin.hpp
@@ -72,7 +72,7 @@ namespace game
 		private:
 			//TODO: modify/delete functions
 			penguin_state state;
-			void move_penguin(uint32_t* p);
+			void move_penguin(uint32_t* p, uint16_t rel_move);
 			int update_moves(uint32_t* p, uint64_t obstacles);
 
 			const uint8_t RED = 0;
-- 
GitLab