File: move.cc

package info (click to toggle)
libosl 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 273,976 kB
  • sloc: cpp: 129,625; ansic: 7,145; ruby: 1,290; makefile: 558; perl: 413; sh: 35
file content (84 lines) | stat: -rw-r--r-- 1,996 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "osl/piece.h"
#include "osl/move.h"
#include "move-phash.c"
#include <boost/static_assert.hpp>
#include <iostream>

namespace osl
{
  BOOST_STATIC_ASSERT(sizeof(Move) == 4);
} //namespace osl

bool osl::Move::isValid() const
{
  if (! isNormal())
    return false;
  const Square from = this->from();
  if (! from.isValid())
    return false;
  const Square to = this->to();
  if (! to.isOnBoard())
    return false;
  return osl::isValid(ptype())
    && osl::isValid(capturePtype())
    && capturePtype()!=KING
    && osl::isValid(player());
}

const osl::Move osl::Move::rotate180() const
{
  if (isPass())
    return Move::PASS(alt(player()));
  if (! isNormal())
    return *this;
  return Move(from().rotate180Safe(), to().rotate180(), ptype(),
	      capturePtype(), isPromotion(), alt(player()));
}

std::ostream& osl::operator<<(std::ostream& os,const Move move)
{
  if (move == Move::DeclareWin())
    return os << "MOVE_DECLARE_WIN";
  if (move.isInvalid())
    return os << "MOVE_INVALID";
  if (move.isPass())
    return os << "MOVE_PASS";
  const Player turn = move.player();
  if (move.isValid())
  {
    if (move.from().isPieceStand()) 
    {
      os << "Drop(" << turn << "," << move.ptype() << "," << move.to() << ")";
    }
    else
    {
      const Ptype capture_ptype=move.capturePtype();
      os << "Move(" << turn << "," << move.ptype() << "," 
	 << move.from() << "->" << move.to() ;
      if (move.promoteMask())
	os << ",promote";
      if (capture_ptype != PTYPE_EMPTY)
	os << ",capture=" << capture_ptype;
      os << ")";
    }
  }
  else
  {
    os << "InvalidMove " << move.from() << " " << move.to() 
       << " " << move.ptypeO() << " " << move.oldPtypeO()
       << " " << move.promoteMask()
       << " " << move.capturePtype() << "\n";
  }
  return os;
}

unsigned int osl::Move::hash() const
{
  assert(capturePtype() == PTYPE_EMPTY);
  return move_phash(intValue());
}

// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End: