Skip to content

Commit

Permalink
Correction d'un bug qui faisait que la probabilité de l'univers de va…
Browse files Browse the repository at this point in the history
…lait pas 1
  • Loading branch information
Mamm846 committed May 26, 2024
1 parent 9ef62c4 commit 84cddb1
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Board/Board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class Board final
* du plateau
*/
void update_board() noexcept;
void update_board_classic() noexcept;

/**
* @brief Mouvement classique d'une pièce qui "saute"
Expand Down
38 changes: 38 additions & 0 deletions src/Board/Board.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,42 @@ Board<N, M>::all_move(
}
}
}
}

template <std::size_t N, std::size_t M>
void Board<N, M>::update_board_classic() noexcept
{
std::size_t size_board = std::size(m_board);
for (std::size_t i{size_board}; i > 0; i--)
{
using namespace std::complex_literals;
if (complex_equal(m_board[i - 1].second, 0i))
{
m_board.erase(std::begin(m_board) + i - 1);
}
else
{
for (std::size_t j{i - 1}; j > 0; j--)
{
if (m_board[i - 1].first == m_board[j - 1].first)
{
double inter = std::pow(std::abs(m_board[j - 1].second), 2)+ std::pow(std::abs(m_board[i - 1].second), 2);
m_board[j - 1].second =std::pow(inter, 1./2 );
m_board.erase(std::begin(m_board) + i - 1);
break;
}
}
}
}
/*std::size_t n_size_board = std::size(m_board);
double all_proba {0};
for (std::size_t i{0}; i<n_size_board; i++)
{
all_proba += std::pow(std::abs(m_board[i].second), 2);
}
all_proba = std::pow(all_proba, 1./2);
for (std::size_t i{0}; i<n_size_board; i++)
{
m_board[i].second /= all_proba;
}*/
}
4 changes: 3 additions & 1 deletion src/Board/move.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ CONSTEXPR void Board<N, M>::move(Move const &movement, std::optional<bool> val_m
{
case TypeMove::NORMAL:
move_classic(movement.normal.src, movement.normal.arv, val_mes);
update_board_classic();
break;
case TypeMove::SPLIT:
move_split(movement.split.src,
Expand All @@ -896,6 +897,7 @@ CONSTEXPR void Board<N, M>::move(Move const &movement, std::optional<bool> val_m
move_promotion(movement, val_mes);
break;
default:
return;
break;
}
//update_board();
}
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ create_test_sourcelist (Tests
test_move_merge_after_split.cpp
test_split_after_split.cpp
test_split_after_split2.cpp
test_multiple_split.cpp
test_split_takes.cpp
)

# add the executable
Expand Down
24 changes: 24 additions & 0 deletions test/test_multiple_split.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <Board.hpp>
#include <Piece.hpp>
#include <Coord.hpp>
#include <TypePiece.hpp>
#include <Move.hpp>
#include <math_utility.hpp>

int test_multiple_split(int argc, char **argv)
{
Board<3> board{
{Piece(), Piece(), B_BISHOP},
{Piece(), B_KING, Piece()},
{Piece(),Piece(),Piece()}};
Move m1 = Move_split(Coord(1, 1), Coord(2, 1), Coord(2, 2));
Move m2 = Move_split(Coord(2, 2), Coord(1, 1), Coord(1,2));
Move m3 = Move_classic(Coord(1, 2), Coord(2, 2));
Move m4 = Move_split(Coord(1, 1), Coord(0, 0), Coord(0, 1));
board.move(m1);
board.move(m2);
board.move(m3);
board.move(m4);
bool res{double_equal(board.get_proba(Coord(0,2)), 1.)};
return !res;
}
24 changes: 24 additions & 0 deletions test/test_split_takes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <Board.hpp>
#include <Piece.hpp>
#include <Coord.hpp>
#include <TypePiece.hpp>
#include <Move.hpp>
#include <math_utility.hpp>

int test_split_takes(int argc, char **argv)
{
Board<3> board{
{Piece(), Piece(), W_BISHOP},
{Piece(), B_KING, Piece()},
{Piece(),Piece(),Piece()}};
Move m1 = Move_split(Coord(1, 1), Coord(2, 1), Coord(2, 0));
Move m2 = Move_split(Coord(2, 1), Coord(1, 1), Coord(2, 2));
Move m3 = Move_classic(Coord(0, 2), Coord(1, 1));
Move m4 = Move_classic(Coord(1, 1), Coord(2, 0));
board.move(m1);
board.move(m2);
board.move(m3);
board.move(m4);
bool res{double_equal(board.get_proba(Coord(2,0)), 1.)};
return !res;
}

0 comments on commit 84cddb1

Please sign in to comment.