Skip to content

Commit

Permalink
fix: add win shapes of caro. 40fccfd#r118737310
Browse files Browse the repository at this point in the history
  • Loading branch information
Joker2770 committed Jun 21, 2023
1 parent 1c99b17 commit 68b141f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/caro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ bool Caro::findShap(Board *board, const pair<int, int>& p_drt)
else
return false;

while (!board->isPosOutOfBoard(p_drt_idx))
while (true)
{
if (STONECOLOR::BLACK == board->getIdxStoneColor(p_drt_idx))
vColor.push_back(1);
else if (STONECOLOR::WHITE == board->getIdxStoneColor(p_drt_idx))
vColor.push_back(2);
else if (board->isPosOutOfBoard(p_drt_idx))
vColor.push_back(3);
else
vColor.push_back(0);

Expand All @@ -66,12 +68,14 @@ bool Caro::findShap(Board *board, const pair<int, int>& p_drt)
reverse(vColor.begin(), vColor.end());
p_drt_idx.first = p_idx.first - p_drt.first;
p_drt_idx.second = p_idx.second - p_drt.second;
while (!board->isPosOutOfBoard(p_drt_idx))
while (true)
{
if (STONECOLOR::BLACK == board->getIdxStoneColor(p_drt_idx))
vColor.push_back(1);
else if (STONECOLOR::WHITE == board->getIdxStoneColor(p_drt_idx))
vColor.push_back(2);
else if (board->isPosOutOfBoard(p_drt_idx))
vColor.push_back(3);
else
vColor.push_back(0);

Expand All @@ -91,7 +95,7 @@ bool Caro::findShap(Board *board, const pair<int, int>& p_drt)
{
for (size_t j = 0; j <= vColor.size() - 7; ++j)
{
for (size_t i = 0; i < 20; ++i)
for (size_t i = 0; i < 34; ++i)
{
if (((WIN_SHAPES[i][0]) == (vColor[j])) &&
((WIN_SHAPES[i][1]) == (vColor[j + 1])) &&
Expand Down
17 changes: 16 additions & 1 deletion src/caro.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include<iostream>
using namespace std;

// 0 - empty, 1 - black, 2 - white, 3 - wall
const int WIN_SHAPES[][7] = {
{1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
Expand All @@ -43,6 +44,13 @@ const int WIN_SHAPES[][7] = {
{1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 0},
{3, 1, 1, 1, 1, 1, 0},
{3, 1, 1, 1, 1, 1, 1},
{3, 1, 1, 1, 1, 1, 2},
{3, 1, 1, 1, 1, 1, 3},
{0, 1, 1, 1, 1, 1, 3},
{1, 1, 1, 1, 1, 1, 3},
{2, 1, 1, 1, 1, 1, 3},
{2, 2, 2, 2, 2, 0, 0},
{0, 2, 2, 2, 2, 2, 0},
{0, 0, 2, 2, 2, 2, 2},
Expand All @@ -52,7 +60,14 @@ const int WIN_SHAPES[][7] = {
{2, 2, 2, 2, 2, 2, 1},
{2, 2, 2, 2, 2, 2, 2},
{0, 2, 2, 2, 2, 2, 2},
{2, 2, 2, 2, 2, 2, 0}};
{2, 2, 2, 2, 2, 2, 0},
{3, 2, 2, 2, 2, 2, 0},
{3, 2, 2, 2, 2, 2, 1},
{3, 2, 2, 2, 2, 2, 2},
{3, 2, 2, 2, 2, 2, 3},
{0, 2, 2, 2, 2, 2, 3},
{1, 2, 2, 2, 2, 2, 3},
{2, 2, 2, 2, 2, 2, 3}};

class Caro final : public rules
{
Expand Down

0 comments on commit 68b141f

Please sign in to comment.