Merge branch 'master' of git+ssh://PesaMac@repo.or.cz/srv/git/GoMoku3D
[GoMoku3D.git] / tmp / protoAI / GameMatrix.cpp
blob3126af5f58580b5f368c97b47d939b3a37af8d0d
1 #include "GameMatrix.h"
3 GameMatrix::~GameMatrix(){
4 if(_matrix)
5 delete[] _matrix;
9 GameMatrix* GameMatrix::_instance=0;
10 int GameMatrix::EmptyPoint=-1;
12 GameMatrix* GameMatrix::create(int d1, int d2, int numPlayers)
14 if (!_instance){
15 _instance = new GameMatrix(d1,d2,numPlayers);
17 return _instance;
20 void GameMatrix::destroy()
22 if (_instance){
23 delete _instance;
24 _instance=0;
28 GameMatrix* GameMatrix::instance()
30 return _instance;
33 bool GameMatrix::check(Point p)
35 int x= p.x(); int y= p.y(); int z= p.z();
36 bool test=_instance->elementAt( x, y, z)==EmptyPoint;
37 if(!test) cout<<"test failed\n";//da togliere
38 return test;
41 int& GameMatrix::elementAt(int x, int y, int z)
43 int dim = _d1*_d2;
44 return _matrix[x*dim*dim + y*dim + z];
47 bool GameMatrix::add(Move m)// fatta senza considerare casi di vittoria
49 Point p= m.coord();//mi ritorna l' oggetto Point di Move
50 if(check(p))
52 int x= p.x(); int y= p.y(); int z= p.z() ;
53 elementAt(x,y,z)=m.playerId();//setto il valora all'id del giocatore
54 _freeCounter--;
55 _lastRound.pop_back();
56 _lastRound.push_front(p);
57 return true;
59 else
60 return false;
63 void GameMatrix::clear(Point p)//setto a -1 il valore del Point
65 this->elementAt(p.x(),p.y(),p.z()) = EmptyPoint;
68 int GameMatrix::numberOfPlayers()
70 return _lastRound.size();//size() metodo const
73 void GameMatrix::setLastRound(QList<Point> round)
75 _lastRound = round;
78 bool GameMatrix::isFull()
80 return (_freeCounter==0);