00001 // pieceValues.cc 00002 #include "osl/container/pieceValues.h" 00003 #include "osl/state/simpleState.h" 00004 #include <boost/foreach.hpp> 00005 #include <iostream> 00006 #include <iomanip> 00007 00008 osl::container:: 00009 PieceValues::PieceValues() 00010 { 00011 } 00012 00013 osl::container:: 00014 PieceValues::~PieceValues() 00015 { 00016 } 00017 00018 int osl::container:: 00019 PieceValues::sum() const 00020 { 00021 int result = 0; 00022 BOOST_FOREACH(int v, *this) 00023 { 00024 result += v; 00025 } 00026 return result; 00027 } 00028 00029 #ifndef MINIMAL 00030 void osl::container:: 00031 PieceValues::showValues(std::ostream& os, const SimpleState& state) const 00032 { 00033 for (int y=1;y<=9;y++) { 00034 os << y; 00035 for (int x=9;x>0;x--) { 00036 const Piece piece = state.pieceOnBoard(Square(x,y)); 00037 os << std::setw(7); 00038 if (piece.isEmpty()) 00039 os << 0; 00040 else 00041 os << (*this)[piece.number()]; 00042 } 00043 os << std::endl; 00044 } 00045 os << "black stand: "; 00046 for (int i=0; i<Piece::SIZE; ++i) 00047 { 00048 const Piece piece = state.pieceOf(i); 00049 if ((piece.owner() == BLACK) 00050 && (piece.square().isPieceStand())) 00051 os << piece.ptype() << " " << (*this)[piece.number()] << " "; 00052 } 00053 os << "\n"; 00054 os << "white stand: "; 00055 for (int i=0; i<Piece::SIZE; ++i) 00056 { 00057 const Piece piece = state.pieceOf(i); 00058 if ((piece.owner() == WHITE) 00059 && (piece.square().isPieceStand())) 00060 os << piece.ptype() << " " << (*this)[piece.number()] << " "; 00061 } 00062 os << "\n"; 00063 os << "total: " << sum() << "\n"; 00064 } 00065 #endif 00066 // ;;; Local Variables: 00067 // ;;; mode:c++ 00068 // ;;; c-basic-offset:2 00069 // ;;; End: