コード例 #1
0
ファイル: chesslegalitytest.cpp プロジェクト: Axure/tagua
void ChessLegalityTest::test_castling() {
  ChessMove oo(Point(4, 7), Point(6, 7));
  
  m_state->board().set(Point(6, 7), ChessPiece());
  {
    ChessMove tmp(oo);
    CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp));
  }
  
  m_state->board().set(Point(5, 7), ChessPiece());
  {
    ChessMove tmp(oo);
    CPPUNIT_ASSERT(m_legality_check->legal(tmp));
  }
  
  m_state->board().set(Point(3, 6), ChessPiece(ChessPiece::BLACK, ChessPiece::PAWN));
  {
    ChessMove tmp(oo);
    CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp));
  }
  
  m_state->board().set(Point(3, 6), ChessPiece());
  m_state->board().set(Point(4, 6), ChessPiece(ChessPiece::BLACK, ChessPiece::PAWN));
  {
    ChessMove tmp(oo);
    CPPUNIT_ASSERT(!m_legality_check->pseudolegal(tmp));
  }
}
コード例 #2
0
ファイル: chessgamestatetest.cpp プロジェクト: Axure/tagua
void ChessGameStateTest::test_promotion() {
  m_state->board().set(Point(7, 1), ChessPiece(ChessPiece::WHITE, ChessPiece::PAWN));
  ChessMove h8B(Point(7, 1), Point(7, 0), ChessPiece::BISHOP);
  h8B.setType(ChessMove::PROMOTION);
  m_state->move(h8B);
  
  CPPUNIT_ASSERT(m_state->board().get(Point(7, 0)) ==
    ChessPiece(ChessPiece::WHITE, ChessPiece::BISHOP));
}
コード例 #3
0
ファイル: chessgamestatetest.cpp プロジェクト: Axure/tagua
void ChessGameStateTest::test_queenside_castling() {
  ChessMove oo(Point(4, 7), Point(2, 7));
  oo.setType(ChessMove::QUEEN_SIDE_CASTLING);
  m_state->move(oo);
  
  CPPUNIT_ASSERT(m_state->board().get(Point(2, 7)) == 
    ChessPiece(ChessPiece::WHITE, ChessPiece::KING));
  CPPUNIT_ASSERT(m_state->board().get(Point(3, 7)) ==
    ChessPiece(ChessPiece::WHITE, ChessPiece::ROOK));
  CPPUNIT_ASSERT(m_state->board().get(Point(0, 7)) == ChessPiece());
}
コード例 #4
0
ファイル: chesslegalitytest.cpp プロジェクト: Axure/tagua
void ChessLegalityTest::test_attack3() {
  m_state->board().set(Point(0, 5), ChessPiece(ChessPiece::BLACK, ChessPiece::KING));
  m_state->board().set(Point(1, 6), ChessPiece(ChessPiece::WHITE, ChessPiece::ROOK)); // b2: pawn -> rook
  CPPUNIT_ASSERT(m_legality_check->attacks(ChessPiece::WHITE, Point(0, 5)));
  
  m_state->board().set(Point(1, 7), ChessPiece()); // remove knight on b1
  CPPUNIT_ASSERT(!m_legality_check->attacks(ChessPiece::WHITE, Point(0, 5)));
  
  m_state->board().set(Point(0, 6), ChessPiece()); // remove pawn on a2
  CPPUNIT_ASSERT(m_legality_check->attacks(ChessPiece::WHITE, Point(0, 5)));
  
  m_state->board().set(Point(0, 7), ChessPiece()); // remove rook on a1
  CPPUNIT_ASSERT(!m_legality_check->attacks(ChessPiece::WHITE, Point(0, 5)));
}
コード例 #5
0
ファイル: chesslegalitytest.cpp プロジェクト: Axure/tagua
void ChessLegalityTest::test_simple_move() {
  ChessMove e4(Point(4, 6), Point(4, 4));
  CPPUNIT_ASSERT(m_legality_check->legal(e4));
  
  ChessMove e5(Point(4, 6), Point(4, 3));
  CPPUNIT_ASSERT(!m_legality_check->pseudolegal(e5));
  
  ChessMove Nf3(Point(6, 7), Point(5, 5));
  CPPUNIT_ASSERT(m_legality_check->legal(Nf3));
  
  ChessMove Bc4(Point(5, 7), Point(2, 4));
  CPPUNIT_ASSERT(!m_legality_check->pseudolegal(Bc4));
  
  {
    ChessMove tmp(Point(5, 7), Point(2, 4));
    m_state->board().set(Point(4, 6), ChessPiece());
    CPPUNIT_ASSERT(m_legality_check->legal(tmp));
  }
  
  ChessMove e6(Point(4, 1), Point(4, 2));
  CPPUNIT_ASSERT(!m_legality_check->pseudolegal(e6));
  
  {
    ChessMove tmp(Point(4, 1), Point(4, 2));
    m_state->switchTurn();
    CPPUNIT_ASSERT(m_legality_check->legal(tmp));
  }
}
コード例 #6
0
ファイル: chessgamestatetest.cpp プロジェクト: Axure/tagua
void ChessGameStateTest::test_capture() {
  m_state->move(ChessMove(Point(4, 6), Point(4, 4))); // e4
  m_state->move(ChessMove(Point(3, 1), Point(3, 3))); // d5
  m_state->move(ChessMove(Point(4, 4), Point(3, 3))); // exd5
  
  CPPUNIT_ASSERT(m_state->board().get(Point(3, 3)) == 
    ChessPiece(ChessPiece::WHITE, ChessPiece::PAWN));
}
コード例 #7
0
ファイル: chesslegalitytest.cpp プロジェクト: Axure/tagua
void ChessLegalityTest::test_promotion() {
  m_state->board().set(Point(7, 1), ChessPiece(ChessPiece::WHITE, ChessPiece::PAWN));
  ChessMove h8Q(Point(7, 1), Point(7, 0), ChessPiece::QUEEN);
  CPPUNIT_ASSERT(!m_legality_check->pseudolegal(h8Q));
  
  ChessMove hxg8R(Point(7, 1), Point(6, 0), ChessPiece::ROOK);
  CPPUNIT_ASSERT(m_legality_check->pseudolegal(hxg8R));
  CPPUNIT_ASSERT(m_legality_check->legal(hxg8R));
  CPPUNIT_ASSERT_EQUAL((int)ChessPiece::ROOK, hxg8R.promoteTo());
}
コード例 #8
0
ファイル: ChessMove.cpp プロジェクト: joaoamaral/k3chess
std::string ChessMove::toString() const
{
   if(promotion==ptNone)
   {
      return CoordPair::toString();
   }
   else
   {
      std::string s;
      s.reserve(5);
      s.append(CoordPair::toString());
      s.push_back(ChessPiece(promotion|pcBlack).toChar());
      return s;
   }
}
コード例 #9
0
ファイル: chessgamestatetest.cpp プロジェクト: Axure/tagua
void ChessGameStateTest::test_en_passant() {
  m_state->move(ChessMove(Point(4, 6), Point(4, 4))); // e4
  m_state->move(ChessMove(Point(7, 1), Point(7, 2))); // h6
  m_state->move(ChessMove(Point(4, 4), Point(4, 3))); // e5
  
  ChessMove d5(Point(3, 1), Point(3, 3));
  d5.setType(ChessMove::EN_PASSANT_TRIGGER);
  m_state->move(d5);
  
  CPPUNIT_ASSERT(m_state->enPassant() == Point(3, 2));
  
  ChessMove exd6(Point(4, 3), Point(3, 2));
  exd6.setType(ChessMove::EN_PASSANT_CAPTURE);
  m_state->move(exd6);
  
  CPPUNIT_ASSERT(m_state->board().get(Point(3, 3)) == ChessPiece());
}
コード例 #10
0
ファイル: chessgamestatetest.cpp プロジェクト: Axure/tagua
void ChessGameStateTest::test_setup() {
  for (int i = 0; i < 8; i++) {
    CPPUNIT_ASSERT_EQUAL(ChessPiece::BLACK,
      m_state->board().get(Point(i, 0)).color());
    CPPUNIT_ASSERT_EQUAL(ChessPiece::BLACK,
      m_state->board().get(Point(i, 1)).color());
    CPPUNIT_ASSERT_EQUAL(ChessPiece::WHITE,
      m_state->board().get(Point(i, 6)).color());
    CPPUNIT_ASSERT_EQUAL(ChessPiece::WHITE,
      m_state->board().get(Point(i, 7)).color());
    CPPUNIT_ASSERT(m_state->board().get(Point(i, 4)) == ChessPiece());
  }
  
  CPPUNIT_ASSERT_EQUAL(ChessPiece::ROOK,
    m_state->board().get(Point(0, 0)).type());
  CPPUNIT_ASSERT_EQUAL(ChessPiece::KING,
    m_state->board().get(Point(4, 7)).type());
  CPPUNIT_ASSERT_EQUAL(ChessPiece::PAWN,
    m_state->board().get(Point(6, 6)).type());
}
コード例 #11
0
ファイル: chessgamestatetest.cpp プロジェクト: Axure/tagua
void ChessGameStateTest::test_simple_move() {
  m_state->move(ChessMove(Point(4, 6), Point(4, 5))); // e4
  CPPUNIT_ASSERT(m_state->board().get(Point(4, 6)) == ChessPiece());
  CPPUNIT_ASSERT(m_state->board().get(Point(4, 5)) == 
    ChessPiece(ChessPiece::WHITE, ChessPiece::PAWN));
}
コード例 #12
0
ファイル: chesslegalitytest.cpp プロジェクト: Axure/tagua
void ChessLegalityTest::test_attack2() {
  m_state->board().set(Point(4, 4), ChessPiece(ChessPiece::BLACK, ChessPiece::QUEEN));
  CPPUNIT_ASSERT(!m_legality_check->attacks(ChessPiece::WHITE, Point(4, 4)));
}
コード例 #13
0
ファイル: chesslegalitytest.cpp プロジェクト: Axure/tagua
void ChessLegalityTest::test_attack1() {
  m_state->board().set(Point(5, 5), ChessPiece(ChessPiece::BLACK, ChessPiece::ROOK));
  CPPUNIT_ASSERT(m_legality_check->attacks(ChessPiece::WHITE, Point(5, 5)));  
}