当前位置: 首页>>代码示例>>C++>>正文


C++ Piece类代码示例

本文整理汇总了C++中Piece的典型用法代码示例。如果您正苦于以下问题:C++ Piece类的具体用法?C++ Piece怎么用?C++ Piece使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Piece类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

bool Game::modSquare(string mod, int color) {
    if(mod.length() != 3)
        return false;

    int loc = Board::toInts(mod.substr(1,2));
    if(loc < 0) return false;

    int x = loc / 10;
    int y = loc % 10;

    Piece * nPiece;
    switch(mod.at(0)) {
    case 'P':
    case 'p':
        nPiece = new Pawn(color, this);
        if(!(color == WHITE && y == 1) && !(color == BLACK && y == 6))
            static_cast<Pawn *>(nPiece)->hasMoved = true;
        break;
    case 'N':
    case 'n':
        nPiece = new Knight(color, this);
        break;
    case 'B':
    case 'b':
        nPiece = new Bishop(color, this);
        break;
    case 'R':
    case 'r':
        nPiece = new Rook(color, this);
        if(!(color == WHITE && y == 0 && (x == 0 || x == 7)) && !(color == BLACK && y == 7 && (x == 0 || x == 7)))
            static_cast<Rook *>(nPiece)->hasMoved = true;
        break;
    case 'Q':
    case 'q':
        nPiece = new Queen(color, this);
        break;
    case 'K':
    case 'k':
        nPiece = new King(color, this);
        setKing(color, nPiece);
        if(!(color == WHITE && y == 0 && x == 4) && !(color == BLACK && y == 7 && x == 4))
            static_cast<King *>(nPiece)->hasMoved = true;
        break;
    case 'X':
    case 'x':
    default:
        nPiece = NULL;
        break;
    }
    if(board->pieces[x][y] != NULL) {

        //is this where the bug was?
        /*bool add = true;
        for(unsigned int i = 0; i < changes[place].size(); i++){
        	if(changes[place][i].moded == board->pieces[x][y]){
        		add = false;
        	}
        }

        if(add){*/
        change_t c;
        c.moded = board->pieces[x][y];
        c.oldLoc =x*10 + y;
        c.newLoc = c.oldLoc;
        c.captured = true;
        c.firstMove = false;
        c.ep = false;

        addChange(c);
        //}
    }
    if(nPiece != NULL) {
        nPiece->setLocation(x, y);
        board->pieces[x][y] = nPiece;

        change_t c;
        c.moded = nPiece;
        c.oldLoc = -11;
        c.newLoc = x*10+y;
        c.captured = false;
        c.firstMove = false;
        c.ep = false;

        addChange(c);
    }
    else
        board->pieces[x][y] = NULL;

    return true;
}
开发者ID:ewsandor,项目名称:flyByKnight,代码行数:90,代码来源:game.cpp

示例2: SS3OPiece

SS3OPiece* CS3OParser::LoadPiece(S3DModel* model, SS3OPiece* parent, unsigned char* buf, int offset)
{
	model->numPieces++;

	Piece* fp = (Piece*)&buf[offset];
	fp->swap(); // Does it matter we mess with the original buffer here? Don't hope so.

	SS3OPiece* piece = new SS3OPiece();
		piece->offset.x = fp->xoffset;
		piece->offset.y = fp->yoffset;
		piece->offset.z = fp->zoffset;
		piece->primType = fp->primitiveType;
		piece->name = (char*) &buf[fp->name];
		piece->parent = parent;
		if (parent != NULL) {
			piece->parentName = parent->name;
		}

	piece->SetVertexCount(fp->numVertices);
	piece->SetVertexDrawIndexCount(fp->vertexTableSize);

	// retrieve each vertex
	int vertexOffset = fp->vertices;

	for (int a = 0; a < fp->numVertices; ++a) {
		Vertex* v = reinterpret_cast<Vertex*>(&buf[vertexOffset]);
			v->swap();

		SS3OVertex sv;
		sv.pos = float3(v->xpos, v->ypos, v->zpos);
		sv.normal = float3(v->xnormal, v->ynormal, v->znormal).SafeANormalize();
		sv.texCoord = float2(v->texu, v->texv);

		piece->SetVertex(a, sv);
		vertexOffset += sizeof(Vertex);
	}


	// retrieve the draw order for the vertices
	int vertexTableOffset = fp->vertexTable;

	for (int a = 0; a < fp->vertexTableSize; ++a) {
		const int vertexDrawIdx = swabDWord(*(int*) &buf[vertexTableOffset]);

		piece->SetVertexDrawIndex(a, vertexDrawIdx);
		vertexTableOffset += sizeof(int);
	}


	piece->goffset = piece->offset + ((parent != NULL)? parent->goffset: ZeroVector);

	piece->SetHasGeometryData(piece->GetVertexDrawIndexCount() != 0);
	piece->SetVertexTangents();
	piece->SetMinMaxExtends();

	model->mins = std::min(piece->goffset + piece->mins, model->mins);
	model->maxs = std::max(piece->goffset + piece->maxs, model->maxs);

	piece->SetCollisionVolume(new CollisionVolume("box", piece->maxs - piece->mins, (piece->maxs + piece->mins) * 0.5f));

	int childTableOffset = fp->children;

	for (int a = 0; a < fp->numchildren; ++a) {
		int childOffset = swabDWord(*(int*) &buf[childTableOffset]);

		SS3OPiece* childPiece = LoadPiece(model, piece, buf, childOffset);
		piece->children.push_back(childPiece);

		childTableOffset += sizeof(int);
	}

	return piece;
}
开发者ID:jamerlan,项目名称:spring,代码行数:73,代码来源:S3OParser.cpp

示例3: getPieceFromVector

Piece RockPaperScissors::getPieceFromVector(const vector<string>& tokens) const {
	Piece p;
	//format: <PIECE_CHAR> <X> <Y>
	switch (tokens[0].at(0)) {
	case 'R':
		p.setrpc(RPC::Rock);
		break;
	case 'P':
		p.setrpc(RPC::Paper);
		break;
	case 'S':
		p.setrpc(RPC::Scissors);
		break;
	case 'B':
		p.setrpc(RPC::Bomb);
		break;
	case 'F':
		p.setrpc(RPC::Flag);
		break;
	case 'J':
		p.setJoker(true);
		//format: J <X> <Y> <PIECE_CHAR>
		switch (tokens[3].at(0)) {
		case 'R':
			p.setrpc(RPC::Rock);
			break;
		case 'P':
			p.setrpc(RPC::Paper);
			break;
		case 'S':
			p.setrpc(RPC::Scissors);
			break;
		case 'B':
			p.setrpc(RPC::Bomb);
			break;
		}
		break;
	}
	return p;
}
开发者ID:yardenm15,项目名称:cpp-project,代码行数:40,代码来源:RockPaperScissors.cpp

示例4: draw

void Board::draw(const Piece &piece)
{
    flood(piece, piece.getType());
}
开发者ID:iZastic,项目名称:SFML-Blueprints,代码行数:4,代码来源:Board.cpp

示例5: buf

void RockPaperScissors::setMove(int lineNumber, const string& line, int playerNumber, Status& currentStatus) {

	//split string by white spaces
	istringstream buf(line);
	istream_iterator<string> beg(buf), end;
	vector<string> tokens(beg, end);
	int fromRow, fromCol, toRow, toCol;

	if (isMoveFormatCorrect(tokens)) {

		fromRow = stoi(tokens[0]) - 1;
		fromCol = stoi(tokens[1]) - 1;
		toRow = stoi(tokens[2]) - 1;
		toCol = stoi(tokens[3]) - 1;

		//player doesn't have a piece at source 
		if (getPlayerOwningCell(fromRow, fromCol) != playerNumber) {
			cout << "Player " << playerNumber << " has no pieces to move at " << fromRow + 1 << "," << fromCol + 1 << " when executing line number " << lineNumber + 1 << ":" << endl \
				<< line << endl;
			currentStatus.setStatus(playerNumber, PossibleStatus::Move_File_Error, lineNumber, line);
			return;
		}

		//piece at source isn't a moving piece
		else if (getPieceAt(fromRow, fromCol).getrpc() != RPC::Rock  && \
			getPieceAt(fromRow, fromCol).getrpc() != RPC::Paper && \
			getPieceAt(fromRow, fromCol).getrpc() != RPC::Scissors) {
			cout << "Player " << playerNumber << " has no mobile pieces at " << fromRow + 1 << "," << fromCol + 1 << " when executing line " << lineNumber + 1 << ":" << endl \
				<< line << endl;
			currentStatus.setStatus(playerNumber, PossibleStatus::Move_File_Error, lineNumber+1, line);
			return;
		}

		//player already has a piece at destination 
		else if (getPlayerOwningCell(toRow, toCol) == playerNumber) {
			cout << "Player " << playerNumber << " already has a " << getPieceAt(toRow, toCol) << " piece at " << toRow + 1 << "," << toCol + 1 << " when executing line number " << lineNumber + 1 << ":" << endl \
				<< line << endl;
			currentStatus.setStatus(playerNumber, PossibleStatus::Move_File_Error, lineNumber, line);
			return;
		}
	}

	//illegal format
	else {
		cout << "Player " << playerNumber << " has a faulty format in line " << lineNumber + 1 << " : " << endl \
			<< line << endl \
			<< "Correct format is:" << endl \
			<< "<FROM_X> <FROM_Y> <TO_X> <TO_Y> [J: <Joker_X> <Joker_Y> <NEW_REP>]" << endl;
		currentStatus.setStatus(playerNumber, PossibleStatus::Move_File_Error, lineNumber, line);
		return;
	}

	//move the piece

	//place piece at new cell
	if (!placePiece(playerNumber, Piece(), fromRow, fromCol, toRow, toCol, lineNumber, line, currentStatus))
		return;

	if (tokens.size() == 8) {
		Cell& c = board[stoi(tokens[5]) - 1][stoi(tokens[6]) - 1];
		if (c.getPlayerOwning() == playerNumber && c.getCellPiece().getisJoker() == true) {
			Piece pTo;
			pTo.setJoker(true);
			switch (tokens[7].at(0)) {
			case 'R':
				pTo.setrpc(RPC::Rock);
				break;
			case 'P':
				pTo.setrpc(RPC::Paper);
				break;
			case 'S':
				pTo.setrpc(RPC::Scissors);
				break;
			case 'B':
				pTo.setrpc(RPC::Bomb);
				break;
			}
			c.setCell(pTo, playerNumber);
		}
		else {
			cout << "Player " << playerNumber << " has no joker piece at " << stoi(tokens[5]) << "," << stoi(tokens[6]) << " when executing line number " << lineNumber + 1 << ":" << endl \
				<< line << endl;
			currentStatus.setStatus(playerNumber, PossibleStatus::Move_File_Error, lineNumber+1, line);
		}
	}
}
开发者ID:yardenm15,项目名称:cpp-project,代码行数:86,代码来源:RockPaperScissors.cpp

示例6: printBoard

void RockPaperScissors::printBoard() {
	char chr = '_';
	for (int i = 0; i < NUM_OF_ROWS; ++i) {
		for (int j = 0; j < NUM_OF_COLS; ++j) {
			Cell& cel = board[i][j];
			Piece p = cel.getCellPiece();
			int playerOwn = cel.getPlayerOwning();
			if (playerOwn == PLAYER_ONE) {
				if (p.getisJoker())
					chr = 'J';
				else {
					switch (p.getrpc()) {
					case RPC::Rock:
						chr = 'R';
						break;
					case RPC::Paper:
						chr = 'P';
						break;
					case RPC::Scissors:
						chr = 'S';
						break;
					case RPC::Bomb:
						chr = 'B';
						break;
					case RPC::Flag:
						chr = 'F';
						break;
					default:
						break;
					}
				}
			}
			else if (playerOwn == PLAYER_TWO) {
				if (p.getisJoker())
					chr = 'j';
				else {
					switch (p.getrpc()) {
					case RPC::Rock:
						chr = 'r';
						break;
					case RPC::Paper:
						chr = 'p';
						break;
					case RPC::Scissors:
						chr = 's';
						break;
					case RPC::Bomb:
						chr = 'b';
						break;
					case RPC::Flag:
						chr = 'f';
						break;
					default:
						break;
					}
				}
			}
			else {
				chr = '_';
			}
			cout << chr;
		}
		cout << endl;
	}
	cout << endl;
}
开发者ID:yardenm15,项目名称:cpp-project,代码行数:66,代码来源:RockPaperScissors.cpp

示例7: LOG

bool SfenParser::parsePosition(const char* arg1,
                               const char* arg2,
                               const char* arg3,
                               const char* /*arg4*/,
                               Position& position) {
    MutablePosition mp;

    {
        int file = 9;
        int rank = 1;
        for (const char* p = arg1; p[0] != '\0'; p++) {
            if (p[0] == '/') {
                if (file != 0) {
                    LOG(warning) << "invalid format: '" << arg1 << '\'';
                    return false;
                }
                if (rank == 9) {
                    LOG(warning) << "invalid format: '" << arg1 << '\'';
                    return false;
                }
                file = 9;
                rank = rank + 1;

            } else if (isdigit(p[0])) {
                int len = p[0] - '0';
                for (int i = 0; i < len; i++) {
                    if (file == 0) {
                        LOG(warning) << "invalid format: '" << arg1 << '\'';
                        return false;
                    }
                    mp.board[Square(file, rank).raw()] = Piece::empty();
                    file = file - 1;
                }

            } else {
                Piece piece = Piece::parseSFEN(p);
                if (piece.isEmpty()) {
                    LOG(warning) << "invalid format: '" << arg1 << '\'';
                    return false;
                }
                mp.board[Square(file, rank).raw()] = piece;
                file = file - 1;
                if (p[0] == '+') {
                    p++;
                }
            }
        }

        if (file != 0 || rank != 9) {
            LOG(warning) << "invalid format: '" << arg1 << '\'';
            return false;
        }
    }

    {
        if (strcmp(arg2, "b") == 0) {
            mp.turn = Turn::Black;
        } else if (strcmp(arg2, "w") == 0) {
            mp.turn = Turn::White;
        } else {
            LOG(warning) << "invalid format: '" << arg2 << '\'';
            return false;
        }
    }

    {
        HAND_EACH(piece) {
            mp.blackHand.set(piece, 0);
            mp.whiteHand.set(piece, 0);
        }

        if (strcmp(arg3, "-") != 0) {
            for (const char* p = arg3; p[0] != '\0'; p++) {
                int num = 1;
                if (isdigit(p[0])) {
                    num = strtol(p, nullptr, 10);
                    p = isdigit(p[1]) ? p + 2 : p + 1;
                }

                Piece piece = Piece::parseSFEN(p);
                if (piece.isEmpty()) {
                    LOG(warning) << "invalid format: '" << arg3 << '\'';
                    return false;
                }

                if (piece.isBlack()) {
                    mp.blackHand.set(piece.type(), num);
                } else {
                    mp.whiteHand.set(piece.type(), num);
                }
            }
        }
    }

    position.initialize(mp);

    return true;
}
开发者ID:sunfish-shogi,项目名称:sunfish4,代码行数:98,代码来源:SfenParser.cpp

示例8: switch

//*****************************************************
bool Board::isValidScoutMove(Piece* const scout, Piece* const destination){
	// temporary piece
	Piece* tmpPiece = 0;
	// valid  and found booleans
	bool valid = true,
       found = false;
	// counter variable
	int i = 0;
	// direction to destination
	// up - 1, right - 2, down - 3, left - 4
	int direction = 0;

	if((scout->getBoardSpace() % 10) == (destination->getBoardSpace() % 10)){
		if(scout->getBoardSpace() > destination->getBoardSpace()){
			direction = 1;
		}else{
			direction = 3;
		}
	}else{
		if(scout->getBoardSpace() > destination->getBoardSpace()){
			direction = 4;
		}else{
			direction = 2;
		}
	}

	switch(direction){
    // above
    case 1:
      i = scout->getBoardSpace() - 10;

      while(!found && i > -1){
        tmpPiece = findPieceAtBoardSpace(i);

        if(tmpPiece != 0){
          if(tmpPiece->getBoardSpace() == destination->getBoardSpace()){
            found = true;
          }

          if(tmpPiece->getBoardSpace() != destination->getBoardSpace() && tmpPiece->getRank() != 0){
            valid = false;
          }
        }else{
          found = true;
          valid = false;
        }

        i -= 10;
      }
    break;

    // to the right of
    case 2:
      i = scout->getBoardSpace() + 1;

      while(!found && i < (((scout->getBoardSpace() / 10) + 1) * 10)){
        tmpPiece = findPieceAtBoardSpace(i);

        if(tmpPiece != 0){
          if(tmpPiece->getBoardSpace() == destination->getBoardSpace()){
            found = true;
          }

          if(tmpPiece->getBoardSpace() != destination->getBoardSpace() && tmpPiece->getRank() != 0){
            valid = false;
          }
        }else{
          found = true;
          valid = false;
        }

        i++;
      }
    break;

    //below
    case 3:
      i = scout->getBoardSpace() + 10;

      while(!found && i < 100){
        tmpPiece = findPieceAtBoardSpace(i);

        if(tmpPiece != 0){
          if(tmpPiece->getBoardSpace() == destination->getBoardSpace()){
            found = true;
          }

          if(tmpPiece->getBoardSpace() != destination->getBoardSpace() && tmpPiece->getRank() != 0){
            valid = false;
          }
        }else{
          found = true;
          valid = false;
        }

        i += 10;
      }
    break;

//.........这里部分代码省略.........
开发者ID:Kylerchrdsn,项目名称:OOP-Strategoo,代码行数:101,代码来源:Board.cpp

示例9: Unit

	// Given a position in the field, it gets the piece on it and determines its possible moves
	std::vector<Position> Board::moves(const Position& position) const {
		std::vector<Position> possibleMoves;

		Piece* p = this->getPiece(position);
		if ((!p) || (!p->isUnit())) {
			return possibleMoves; // case empty or not a Unit (cannot move)
		}

		Position from = p->getPosition();

		// Scout case
		if(p->getValue()==SCOUT) {
			for(int i=1+from.x;i<10;i++) { // go right
				if(this->isCorrectRelativeMove(from, Position(i, from.y))) {
					possibleMoves.push_back(Position(i, from.y));
					if(!this->isCaseFree(Position(i, from.y))) {
						break; // stop if the position contains something
					}
				}
				else {
					break;
				}
			}
			for(int i=from.x-1;i>=0;i--) { // go left
				if(this->isCorrectRelativeMove(from, Position(i, from.y))) {
					possibleMoves.push_back(Position(i, from.y));
					if(!this->isCaseFree(Position(i, from.y))) {
						break; // stop if the position contains something
					}
				}
				else {
					break;
				}
			}
			for(int i=1+from.y;i<10;i++) { // go up
				if(this->isCorrectRelativeMove(from, Position(from.x, i))) {
					possibleMoves.push_back(Position(from.x, i));
					if(!this->isCaseFree(Position(from.x, i))) {
						break; // stop if the position contains something
					}
				}
				else {
					break;
				}
			}
			for(int i=from.y-1;i>=0;i--) { // go down
				if(this->isCorrectRelativeMove(from, Position(from.x, i))) {
					possibleMoves.push_back(Position(from.x, i));
					if(!this->isCaseFree(Position(from.x, i))) {
						break; // stop if the position contains something
					}
				}
				else {
					break;
				}
			}
		}
		else { // normal case
			Position toRight = Position(1+from.x, from.y);
			if(this->isCorrectRelativeMove(from, toRight)) {
				possibleMoves.push_back(toRight);
			}
			Position toLeft = Position(from.x-1, from.y);
			if(this->isCorrectRelativeMove(from, toLeft)) {
				possibleMoves.push_back(toLeft);
			}
			Position toUp = Position(from.x, 1+from.y);
			if(this->isCorrectRelativeMove(from, toUp)) {
				possibleMoves.push_back(toUp);
			}
			Position toDown = Position(from.x, from.y-1);
			if(this->isCorrectRelativeMove(from, toDown)) {
				possibleMoves.push_back(toDown);
			}
		}

		return possibleMoves;
	}
开发者ID:Sylveurdance,项目名称:Stratego,代码行数:79,代码来源:Board.cpp

示例10: MakePieces

void MakePieces() {
	Piece t = Piece(3, 0.0, 0.0, 0.0);
	t.Set(0, 0, true);
	t.Set(1, 0, true);
	t.Set(2, 0, true);
	t.Set(1, 1, true);
	t.Set(1, 2, true);

	Piece i = Piece(3, 0.0, 0.0, 0.0);
	i.Set(0, 0, true);
	i.Set(0, 1, true);
	i.Set(0, 2, true);

	Piece lr = Piece(3, 0.0, 0.0, 0.0);
	lr.Set(0, 0, true);
	lr.Set(0, 1, true);
	lr.Set(0, 2, true);
	lr.Set(1, 2, true);

	Piece ll = Piece(3, 0.0, 0.0, 0.0);
	ll.Set(1, 0, true);
	ll.Set(1, 1, true);
	ll.Set(1, 2, true);
	ll.Set(0, 2, true);

	Piece sqr = Piece(2, 0.0, 0.0, 0.0);
	sqr.Set(0, 0, true);
	sqr.Set(0, 1, true);
	sqr.Set(1, 0, true);
	sqr.Set(1, 1, true);

	Piece zl = Piece(3, 0.0, 0.0, 0.0);
	zl.Set(0, 0, true);
	zl.Set(0, 1, true);
	zl.Set(1, 1, true);
	zl.Set(2, 1, true);

	Piece zr = Piece(3, 0.0, 0.0, 0.0);
	zr.Set(2, 0, true);
	zr.Set(1, 0, true);
	zr.Set(1, 1, true);
	zr.Set(0, 1, true);

	pieces.clear();
	pieces.push_back(sqr);
	pieces.push_back(t);
	pieces.push_back(i);
	pieces.push_back(lr);
	pieces.push_back(ll);
	pieces.push_back(zl);
	pieces.push_back(zr);
}
开发者ID:robbor78,项目名称:OpenGLTetris,代码行数:52,代码来源:main.cpp

示例11: Draw

void NextPiece::Draw(Bitmap &canvas) {
	if (piece) {
		canvas.Clear(skin->c_face);
		piece->Draw(canvas, 0, 0);
	}
}
开发者ID:bambams,项目名称:ma5king,代码行数:6,代码来源:ex05.cpp

示例12: test_piece_turntaking

// Taking turns
void test_piece_turntaking(ErrorContext &ec, unsigned int numRuns) {
    bool pass;

    // Run at least once!!
    assert(numRuns > 0);

    ec.DESC("--- Test - Piece - Taking turns ---");

    for (int run = 0; run < numRuns; run++) {

        ec.DESC("3x3, manual, simple agent going for a resource");

        {
            Game g(3, 3);

            // populate the game environment
            g.addFood(0, 0); g.addAdvantage(2, 1);

            // create a Simple, passing it the game and a position
            Simple s(g, Position(1, 1), Game::STARTING_AGENT_ENERGY);

            // create an upcast pointer to the agent for polymorphic turn taking
            Piece *piece = &s;

            // get the Surroundings for the agent's position from the Game
            Surroundings surr = g.getSurroundings(Position(1, 1));

            // call takeTurn on the Piece pointer to the agent
            ActionType action = piece->takeTurn(surr);

            // if there is a resource, it should ask to there
            // and so on...
            pass = (action == ActionType::NW) || (action == ActionType::S);
            if (! pass) std::cout << action << std::endl;

            ec.result(pass);
        }

        ec.DESC("3x3, manual, simple agent moving to an empty position");

        {
            Game g(3, 3);

            // populate the game environment
            g.addStrategic(0, 1); g.addSimple(1, 1);

            // create a Simple, passing it the game and a position
            Simple s(g, Position(0, 2), Game::STARTING_AGENT_ENERGY);

            // create an upcast pointer to the agent for polymorphic turn taking
            Piece *piece = &s;

            // get the Surroundings for the agent's position from the Game
            Surroundings surr = g.getSurroundings(Position(0, 2));

            // call takeTurn on the Piece pointer to the agent
            ActionType action = piece->takeTurn(surr);

            // if there is a resource, it should ask to there
            // and so on...
            pass = (action == ActionType::S);
            if (! pass) std::cout << action << std::endl;

            ec.result(pass);
        }

        ec.DESC("3x3, manual, simple agent staying in place, not attacking");

        {
            Game g(3, 3);

            // populate the game environment
            g.addStrategic(0, 1); g.addSimple(1, 1); g.addSimple(1, 2);

            // create a Simple, passing it the game and a position
            Simple s(g, Position(0, 2), Game::STARTING_AGENT_ENERGY);

            // create an upcast pointer to the agent for polymorphic turn taking
            Piece *piece = &s;

            // get the Surroundings for the agent's position from the Game
            Surroundings surr = g.getSurroundings(Position(0, 2));

            // call takeTurn on the Piece pointer to the agent
            ActionType action = piece->takeTurn(surr);

            // if there is a resource, it should ask to there
            // and so on...
            pass = (action == ActionType::STAY);
            if (! pass) std::cout << action << std::endl;

            ec.result(pass);
        }

        ec.DESC("3x3, manual, resources don't move");

        {
            Game g(3, 3);

//.........这里部分代码省略.........
开发者ID:JBianca,项目名称:ucd-csci2312-pa4,代码行数:101,代码来源:GamingTests.cpp

示例13: ActionResult

/**
@return The result of the action the player made. WRONG_COLOR, PIECE_SELECTED, PIECE_MOVED, INVALID_POSITION.
*/
ActionResult Player::performAction()
{
	// Translate mouse coordinate to sqaure coordinates
	Position pos = mBoard->toGridPos(gInput->mousePosition());
	ActionResult action;
	bool moved = false;

	// No piece is selected
	if(gInput->keyPressed(VK_LBUTTON) && mSelectedPiece == NULL)
	{
		Piece* piece = mBoard->getPieceAt(pos.x, pos.y);
		// A piece was pressed
		if(piece != NULL)
		{
			// The piece has another color than the players
			if(piece->getColor() != getColor())	{
				// Return wrong color msg
				action = ActionResult(WRONG_COLOR, pos);
				gSound->playEffect(ILLEGAL_SOUND);
			}
			else	{
				mSelectedPiece = piece;
				mBoard->setSelected(pos.x, pos.y);
				// Return piece selected msg
				action = ActionResult(PIECE_SELECTED, pos);
			}
		}
	}
	// A piece is already selected
	else if(gInput->keyPressed(VK_LBUTTON) && mSelectedPiece != NULL)
	{
		Piece* piece = mBoard->getPieceAt(pos.x, pos.y);
		Position oldPos = mSelectedPiece->getPos();
		// Was it a piece of the same color that was pressed? - Change the selected piece
		if(piece != NULL && piece->getColor() == getColor())
		{
			mSelectedPiece = piece;
			action = ActionResult(PIECE_SELECTED, pos);
		}
		// Didn't select a piece of the same color as self
		else
		{
			// The piece can move to the pressed location
			if(mBoard->validMove(mSelectedPiece, pos.x, pos.y))	
			{
				// A piece was captured
				if(piece != NULL)	{
					handleCapture(piece->getColor(), piece->getType());
					mBoard->removePiece(piece);
					pieceCapturedSound();
				}

				// Return piece moved msg
				action = ActionResult(PIECE_MOVED, pos, mSelectedPiece->getPos());

				// Update the selected piece's position
				mSelectedPiece->setPos(pos.x, pos.y);
				mSelectedPiece->moved();

				// Was it castling?
				if(mSelectedPiece->getType() == KING && abs(mSelectedPiece->getPos().x - oldPos.x) > 1)	{
					handleCastling(mSelectedPiece);
					gSound->playEffect(CASTLE_SOUND);
				}
				else
					pieceMovedSound();

				mSelectedPiece = NULL;
			}
			// Can't move to the pressed location
			else
			{
				// Return invalid position or checked msg
				if(mBoard->resultsInCheck(mSelectedPiece, pos.x, pos.y))
					action = ActionResult(GETS_CHECKED, mBoard->getPiece(KING, mSelectedPiece->getColor())->getPos());
				else	{
					if(pos.x >= 0 && pos.x <= 7 && pos.y >= 0 && pos.y <= 7)
						action = ActionResult(INVALID_POSITION, pos);
					else
						action = ActionResult(PIECE_SELECTED, Position(-10, -10));
				}
				gSound->playEffect(ILLEGAL_SOUND);
				mSelectedPiece = NULL;
			}
		}
	}

	// Return the action
	return action;
}
开发者ID:fobnn,项目名称:Banzai,代码行数:93,代码来源:Player.cpp

示例14: amountOfSystemItems

SnakesAndLadders::SnakesAndLadders():Game(2,10,10), amountOfSystemItems(2) {
  // Set srand a more random die roll.
  srand(time(NULL));

  // systemItems holds the snakes and ladders.
  this->systemItems = new Player[amountOfSystemItems];

  // This is simply just used an a reference instead of trying to convert
  // Coords to square ids.
  this->squareRefs = new Square*[100];

  // Setup the Players.
  const int playerTypes = 1;
  const int maxPlayerPieces = 1;

  vector<string> player1PieceTypes(playerTypes);
  vector<string> player2PieceTypes(maxPlayerPieces);

  // Set their character representations.
  player1PieceTypes[0] = FRED "◎";
  player2PieceTypes[0] = FBLUE "◎";

  players[0] = new SLPlayer(playerTypes,player1PieceTypes,maxPlayerPieces);
  players[1] = new SLPlayer(playerTypes,player2PieceTypes,maxPlayerPieces);

  // Setup the snakes and ladders.
  const int systemTypes = 2;
  const int maxSystemPieces = 16;
  vector <string> system1PieceTypes(systemTypes);
  vector <string> system2PieceTypes(systemTypes);

  // Set the start point snake/ladder character representations.
  system1PieceTypes[0] = FVIOLET "S";
  system1PieceTypes[1] = FGREEN "L";

  // Set the end point snake/ladder character representations.
  system2PieceTypes[0] = FORANGE "S";
  system2PieceTypes[1] = FMAGENTA "L";

  systemItems[0] = Player(systemTypes,system1PieceTypes,maxSystemPieces);
  systemItems[1] = Player(systemTypes,system2PieceTypes,maxSystemPieces);

  // Setup all the squares.
  int totalPlayers = amountOfPlayers + amountOfSystemItems;

  string start[] = {BBLACK,BGRAY};
  string end = RESET;

  int identifier = 0;

  int counter = 100;

  for(int i=0; i<rows; i++) {
    for(int j=0; j<columns; j++) {

      grid[i][j] = Square(counter,start[identifier],end,totalPlayers,
                          Coord(j,i));
      squareRefs[counter-1] = &grid[i][j];

      counter += (i % 2 == 0) ? -1 : 1;
      identifier = (identifier + 1)%2;
    }
    counter -= (i % 2 == 0) ? 9 : 11;
    identifier = (identifier + 1)%2;
  }

  // Add the players to the starting square.
  if(players[0]->hasRoomForPiece() && players[1]->hasRoomForPiece()) {
    Piece* player1Piece = new SrcPiece(*players[0],Coord(0,9));
    Piece* player2Piece = new SrcPiece(*players[1],Coord(0,9));
    squareRefs[0]->addPiece(0, players[0]->addPiece(player1Piece));
    squareRefs[0]->addPiece(1, players[1]->addPiece(player2Piece));
  }

  Coord snakes[maxSystemPieces/2][2] = {
    {squareToCoordinate(20),squareToCoordinate(17)},
    {squareToCoordinate(33),squareToCoordinate(7)},
    {squareToCoordinate(44),squareToCoordinate(22)},
    {squareToCoordinate(52),squareToCoordinate(31)},
    {squareToCoordinate(63),squareToCoordinate(54)},
    {squareToCoordinate(85),squareToCoordinate(67)},
    {squareToCoordinate(94),squareToCoordinate(71)},
    {squareToCoordinate(99),squareToCoordinate(61)},
  };
  Coord ladders[maxSystemPieces/2][2] = {
    {squareToCoordinate(9),squareToCoordinate(29)},
    {squareToCoordinate(15),squareToCoordinate(26)},
    {squareToCoordinate(24),squareToCoordinate(46)},
    {squareToCoordinate(40),squareToCoordinate(60)},
    {squareToCoordinate(64),squareToCoordinate(76)},
    {squareToCoordinate(69),squareToCoordinate(87)},
    {squareToCoordinate(83),squareToCoordinate(98)},
    {squareToCoordinate(48),squareToCoordinate(68)}
  };

  Piece* source;
  Piece* destination;

  // Place all the snakes onto the board.
  for(int i=0; i<maxSystemPieces/amountOfSystemItems; i++) {
//.........这里部分代码省略.........
开发者ID:BroganD1993,项目名称:CBG,代码行数:101,代码来源:SnakesAndLadders.cpp

示例15: spawnSpecificPiece

void GameMechanics::spawnNextPieceFromQueue() {
	Piece nextFromQueue = _pieceQueue.PushNewPiece(_pieceFactory.CreateRandomPiece(GameSettings::BlockSizeForQueue));
	
	spawnSpecificPiece(nextFromQueue.GetPieceType());
}
开发者ID:marlowe-ml,项目名称:Voltricity,代码行数:5,代码来源:GameMechanics.cpp


注:本文中的Piece类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。