From 2307450584bf1dc80b58e6397a54ea013490b2c8 Mon Sep 17 00:00:00 2001
From: Mikael Le <mikael.le@insa-rennes.fr>
Date: Tue, 20 Oct 2015 11:51:05 +0200
Subject: [PATCH] mod 2 mika

---
 src/game/morpion.cpp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/game/morpion.cpp b/src/game/morpion.cpp
index 84c5ddb..eba70a6 100644
--- a/src/game/morpion.cpp
+++ b/src/game/morpion.cpp
@@ -67,7 +67,7 @@ namespace game
 
 	uint8_t morpion::current_player() const
 	{
-		return state.total_moves & 1 ? CIRCLE : CROSS; // CROSS pair, CIRCLE impair
+		return state.total_moves & 1 ? CIRCLE : CROSS; // CROSS even, CIRCLE odd
 	}
 
 	int morpion::value(uint8_t player) const
@@ -91,12 +91,20 @@ namespace game
 
 	void morpion::update_win()
 	{
-		//TODO: Implement
+		if(has_won(state.cross_bitboard))
+			state.first_player_win = true;
+		else if(has_won(state.circle_bitboard))
+			state.second_player_win = true;
 	}
 
-	bool morpion::has_won(uint64_t bitboard)
+	bool morpion::has_won(uint16_t bitboard)
 	{
-		//TODO: Implement
+		if(bitboard == ROW1_MASK || bitboard == ROW2_MASK || bitboard == ROW3_MASK) // Check vertical |
+			return true;
+		if(bitboard == COL1_MASK || bitboard == COL2_MASK || bitboard == COL3_MASK) // Check horizontal _
+			return true;
+		if(bitboard == DIA1_MASK || bitboard == DIA2_MASK) // Chack diagonal \ /
+			return true;
 		return false;
 	}
 
-- 
GitLab