File: pieceValues.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 (69 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (2)
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
// pieceValues.cc
#include "osl/container/pieceValues.h"
#include "osl/state/simpleState.h"
#include <boost/foreach.hpp>
#include <iostream>
#include <iomanip>

osl::container::
PieceValues::PieceValues()
{
}

osl::container::
PieceValues::~PieceValues()
{
}

int osl::container::
PieceValues::sum() const
{
  int result = 0;
  BOOST_FOREACH(int v, *this)
  {
    result += v;
  }
  return result;
}

#ifndef MINIMAL
void osl::container::
PieceValues::showValues(std::ostream& os, const SimpleState& state) const
{
  for (int y=1;y<=9;y++) {
    os << y;  
    for (int x=9;x>0;x--) {
      const Piece piece = state.pieceOnBoard(Square(x,y));
      os << std::setw(7);
      if (piece.isEmpty())
	os << 0;
      else
	os << (*this)[piece.number()];
    }
    os << std::endl;
  }
  os << "black stand: ";
  for (int i=0; i<Piece::SIZE; ++i)
  {
    const Piece piece = state.pieceOf(i);
    if ((piece.owner() == BLACK)
	&& (piece.square().isPieceStand()))
      os << piece.ptype() << " " << (*this)[piece.number()] << " ";
  }
  os << "\n";
  os << "white stand: ";
  for (int i=0; i<Piece::SIZE; ++i)
  {
    const Piece piece = state.pieceOf(i);
    if ((piece.owner() == WHITE)
	&& (piece.square().isPieceStand()))
      os << piece.ptype() << " " << (*this)[piece.number()] << " ";
  }
  os << "\n";
  os << "total: " << sum() << "\n";
}
#endif
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End: