Example #1
0
const char *
History::load(LevelMap *map, const char *_str) {
  Move *m;
  int x = map->xpos();
  int y = map->ypos();

  clear();
  while (*_str != '\0' && *_str != '-') {
    m = new Move(x, y);
    _str = m->load(_str);
    if (_str == 0) return 0;
    x = m->finalX();
    y = m->finalY();
    past_.append(m);
    if (!m->redo(map)) {
      //printf("redo failed: %s\n", _str);
      //abort();
      return 0;
    }
  }
  if (*_str != '-') return 0;

  _str++;
  while (*_str != '\0') {
    m = new Move(x, y);
    _str = m->load(_str);
    if (_str == 0) return 0;
    x = m->finalX();
    y = m->finalY();
    future_.append(m);
  }

  return _str;
}
Example #2
0
void OukBoard::updateCounter(Move m, int increment)
{
	Side side = sideToMove();
	int source = m.sourceSquare();
	int target= m.targetSquare();

	if (source == m_initialSquare[side][King]
	||  target == m_initialSquare[side][King])
		m_moveCount[side][King] += increment;

	if (source == m_initialSquare[side][Maiden]
	||  target == m_initialSquare[side][Maiden])
		m_moveCount[side][Maiden] += increment;
}
Example #3
0
void MonteCarlo::updateFilter(Move delta, vector<Observation>& obs) {
	applyMoveToParticles(delta);

	if ( obs.size() != 0 && ( delta.getX() == 0 && delta.getY() == 0 && delta.getTheta() == 0))
	  updateParticleProbabilities(obs);

	resample();

	//TODO: do not do it twice
	//we are doing it in resample but before introducing new particles.
	normalizeParticleProbabilities();

	debug(obs);
}
Example #4
0
void Board::play(const Move& m)
{
	if (!m.isValid(this))
	{
		QMessageBox::critical(NULL, "Invalid move", "Invalid move");
		return;
	}

	m.updateBoard(this);
	nbMovesLeft_--;

	undo_.addState(stateString());
	blackPlays_ = !blackPlays_;
}
void ICP::DcGS(void) const
{
  // Go search

  NoParameters();
  if (IsGameOver()) ReportGameOver();
  else
  {
    Move move;

    FindMove(move);
    PrintFSL(fsLbMove); move.Print(stateptr->FetchSearchFEnv()); PrintNL();
  };
}
Example #6
0
TEST(AttackTest, AttackTargetBug) {
    MyBot bot;
    ifstream state("test/test6.log");
    parse_state(bot, state);

    Move move;
    move.add(FutureOrder(ally, 30, 2, 5, 3));

    Simulator sim(bot.game(), bot.map(), 0);
    sim.simulate(move, SIM_DEPTH, true);

    vector<target_t> targets = sim.select_targets(ally);
    EXPECT_TRUE(std::find_if(targets.begin(), targets.end(), target_kind_comp(attack)) == targets.end());
}
Example #7
0
void
Position::doMove(Lookup& lookup, Move const& move)
{
	Square to = move.to();

	if (move.isCastling())
	{
		sq::Rank	rank		= sq::rank(to);
		Byte		pieceNum	= lookup[move.from()];

		if (move.isShortCastling())
		{
			lookup[sq::make(sq::FyleF, rank)] = m_rookNumbers[castling::kingSideIndex(move.color())];
			lookup[sq::make(sq::FyleG, rank)] = pieceNum;
		}
		else
		{
			lookup[sq::make(sq::FyleD, rank)] = m_rookNumbers[castling::queenSideIndex(move.color())];
			lookup[sq::make(sq::FyleC, rank)] = pieceNum;
		}
	}
	else if (__builtin_expect(!move.isNull(), 0))
	{
		lookup[to] = lookup[move.from()];
	}
}
void GameWindow::commandExecuted(Move& cmd){
   
   	if( this->serverProxy->getMe() == cmd.getTo() )
		messageLabel.setText(cmd.getMainMsg());
	else
		messageLabel.setText(cmd.getSecMsg());
		
	if ( cmd.isValid() ){	
		//cambia estado a populating 
		ReferenceCountPtr<ClientState> popu = new ClientPopulating(*this);
		this->setState(popu);
	}
	//sino es valido sigo en mismo estado
}
	virtual inline void DoFutilityPruning01(
		bool& isContinue,
		bool& INCHECK,
		bool& givesCheck,
		Move& move,
		Move& ttMove,
		ScoreIndex& futilityScore,
		ScoreIndex& futilityBase,
		Position& pos,
		ScoreIndex& beta,
		ScoreIndex& bestScore,
		const Depth depth
		)const override {
		// 非PVノードのとき☆(^q^)
		if (!INCHECK // 駒打ちは王手回避のみなので、ここで弾かれる。
			&& !givesCheck
			&& move != ttMove)
		{
			futilityScore =
				futilityBase + PieceScore::GetCapturePieceScore(pos.GetPiece(move.To()));
			if (move.IsPromotion()) {
				futilityScore += PieceScore::GetPromotePieceScore(move.GetPieceTypeFrom());
			}

			if (futilityScore < beta) {
				bestScore = std::max(bestScore, futilityScore);
				isContinue = true;
				return;
			}

			// todo: MovePicker のオーダリングで SEE してるので、ここで SEE するの勿体無い。
			if (futilityBase < beta
				&& depth < Depth0
				&&
				(
					pos.GetTurn()==Color::Black
					?
					pos.GetSee1<Color::Black,Color::White>(move, beta - futilityBase)
					:
					pos.GetSee1<Color::White,Color::Black>(move, beta - futilityBase)
					)
				<= ScoreZero)
			{
				bestScore = std::max(bestScore, futilityBase);
				isContinue = true;
				return;
			}
		}
	}
Example #10
0
bool SGFNode::getMoveProperty(vector<Move>& m, string prop, int colour) const
{
	vector<string> p;
	if(!getProperty(prop, p))
		return false;
	m.clear();
	Move move;
	for(int i=0;i<p.size();i++) {
		move.setX(Move::SGFToX(p.at(i)));
		move.setY(Move::SGFToY(p.at(i)));
		move.setColour(colour);
		m.push_back(move);
	}
	return true;
}
Example #11
0
string MoveToStr(Move mv)
{
  string s = FldToStr(mv.From()) + FldToStr(mv.To());

  switch (mv.Promotion())
  {
    case QW: case QB: s += "q"; break;
    case RW: case RB: s += "r"; break;
    case BW: case BB: s += "b"; break;
    case NW: case NB: s += "n"; break;
    default: break;
  }

  return s;
}
void ICP::DcTB(void) const
{
  // Take back move

  NoParameters();
  if (stateptr->GetUnDoCount() == 0) PrintFS(fsUdNoTakeBackAvail);
  else
  {
    const Move move = stateptr->FetchLastMove();

    stateptr->Unplay();
    PrintFSL(fsLbUnplayedMove); move.Print(stateptr->FetchSearchFEnv()); PrintNL();
    CondShowBoard();
  };
}
bool ConnectFour::Board::addMove(const Move& move)
{
    if(!isInBounds(move))
        return false;

    m_solved = m_solved || testMove(move);
    m_board[move.column()].push_back(move.player());

    if(m_solved)
        m_winningPlayer = &(move.player());
    if(m_board[move.column()].size() == COLUMN_SIZE)
        ++m_filledColumns;

    return m_solved;
}
Example #14
0
int main()
{
	Move one(5,12.5);
	Move two(0,2.50);

	Move three =one.add(two);
	cout<<"Move Three (one+two) :" <<endl;
	three.showmove();

	cout << "Reset Move Three :" << endl;
	three.reset();
	three.showmove();

	return 0;
}
Example #15
0
void Machine::move(const Move &move) {
  // Measure
  distance += move.getDistance();
  time += move.getTime();

  // Output
  if (moveStream.isNull() && !outputMoves.empty()) {
    if (outputMoves == "-") moveStream = SmartPointer<ostream>::Phony(&cout);
    else moveStream = SystemUtilities::oopen(outputMoves);
  }

  if (!moveStream.isNull()) *moveStream << move << endl;

  LOG_INFO(3, "Machine: Move to " << move.getEndPt());
}
Example #16
0
inline void Board::PlayLegal (const Move& move) {
	ASSERT(IsValidMove(move));
	uint pos = move.GetLocation().GetPos();
	if (move.GetPlayer() == Player::First()) {
		_board[pos] = pos;
		MakeUnion(pos);
	} else {
		_board[pos] = -1;
	}
	uint fast_map_pos = _reverse_fast_field_map[pos];
	uint replace_pos = _fast_field_map[--_moves_left];
	_fast_field_map[fast_map_pos] = replace_pos;
	_reverse_fast_field_map[replace_pos] = fast_map_pos;
	_current = _current.Opponent();
}
Example #17
0
/*
 * Returns true if s1-s2 is a psudo legal bishop move.
 * This is the case if the move changes rank and file
 * the same amount, and no piece is blocking the way.
 */
bool Position::psudoLegalBishop(Move m) {
  Square s1 = m.getFrom(), s2 = m.getTo();
  int d_rank = rank_diff(s1, s2);
  int d_file = file_diff(s1, s2);
  if (abs(d_rank) != abs(d_file)) return false;

  int rank_sign = d_rank < 0 ? -1 : 1;
  int file_sign = d_file < 0 ? -1 : 1;
  for (int i = 1; i < abs(d_file); i++) {
    if (occupied(Square(s1 + i*D_EAST*file_sign + i*D_NORTH*rank_sign))) {
      return false;
    }
  }
  return true;
}
Example #18
0
bool Move::operator<(Move const& m) const
{
	int sp = getSpecial();
	int msp = m.getSpecial();
	if(sp==PIECE_KNIGHT || sp==PIECE_ROOK || sp==PIECE_BISHOP || msp==PIECE_QUEEN || msp==PIECE_KING || msp==PIECE_PAWN)
	{
		return true;
	}
	else if(sp==PIECE_QUEEN || sp==PIECE_KING || sp==PIECE_PAWN || msp==PIECE_KNIGHT || msp==PIECE_ROOK || msp==PIECE_BISHOP)
	{
		return false;
	}
	int c = getCapturedPiece();
	int mc = m.getCapturedPiece();
	int cap = CapturedPiecePriority[c];
	int mcap = CapturedPiecePriority[mc];
	if(cap<mcap)
	{
		return true;
	}
	else if(cap>mcap)
	{
		return false;
	}
	else
	{
		int mov = MovingPiecePriority[c][getMovingPiece()];
		int mmov = MovingPiecePriority[mc][m.getMovingPiece()];
		if(mov<mmov)
		{
			return true;
		}
		else if(mmov>mov)
		{
			return false;
		}
		else
		{
			if(ToPriority[getTo()]<ToPriority[m.getTo()])
			{
				return true;
			}
			else
				return false;
		}
	}
	return false;
}
Example #19
0
MovePicker::MovePicker(const Position& pos, const Move ttm, const Depth depth,
					   const History& history, SearchStack* searchStack, const Score beta)
	: pos_(pos), history_(history), depth_(depth)
{
	assert(Depth0 < depth);

	legalMoves_[0].score = INT_MAX; // 番兵のセット
	currMove_ = lastMove_ = firstMove();
	captureThreshold_ = 0;
	endBadCaptures_ = legalMoves_ + MaxLegalMoves - 1;
	ss_ = searchStack;

	if (pos.inCheck()) {
		phase_ = EvasionSearch;
	}
	else {
		phase_ = MainSearch;

		killerMoves_[0].move = searchStack->killers[0];
		killerMoves_[1].move = searchStack->killers[1];

		if (ss_ != nullptr && ss_->staticEval < beta - CapturePawnScore && depth < 3 * OnePly) {
			captureThreshold_ = -CapturePawnScore;
		}
		else if (ss_ != nullptr && beta < ss_->staticEval) {
			captureThreshold_ = beta - ss_->staticEval;
		}
	}

	ttMove_ = (!ttm.isNone() && pos.moveIsPseudoLegal(ttm) ? ttm : Move::moveNone());
	lastMove_ += (!ttMove_.isNone());
}
/* 
* Returns vector of all legal moves for a given side
*/
vector<Move *> Board::getLegalMoves(Side side){
    vector<Move *> possibleMoves;
    Move* m = new Move(0, 0);
    for (int i = 0; i < 8; i++){
        m->setX(i);
        for (int j = 0; j < 8; j++){
            m->setY(j);
            if (checkMove(m, side) == true){

                Move* good = new Move(i, j);
                possibleMoves.push_back(good);
            }
        }   
    }
    return possibleMoves;
}
int AlphaBetaPruning::FillValidMoves(Move m[], Board &BBoard)
{
    int iNumberOfEntries = 0;
    int iColumns = BBoard.GetNumberOfColumns();
    Move MTemp;
    for (int i = 0; i < iColumns; i++)
    {
        MTemp.SetValues(i);
        if (BBoard.IsValid(MTemp))
        {
            m[iNumberOfEntries] = MTemp;
            iNumberOfEntries++;
        }
    }
    return iNumberOfEntries;
}
Example #22
0
void
History::save(QString &_str) {
  Move *m = past_.first();

  while (m != 0) {
    m->save(_str);
    m = past_.next();
  }
  _str += '-';

  m = future_.first();
  while (m != 0) {
    m->save(_str);
    m = future_.next();
  }
}
Example #23
0
bool Battle::willMoveHit(Pokemon& attacking, Pokemon& defending, Move& move)
{
    // get the moves acc
    float accuracy = move.getAccuracy();

    // if acc is set to always hit, no calculation is needed; it will hit
    if(accuracy == ALWAYS_HIT)
    {
        return true;
    }
    else if(accuracy == HIT_UNLESS_SEMI_INVUL)
    {
        return true;
    }

    // if is a normal value, calculate it
    else
    {
        // calculate the probability of the move hitting
        float hitProb = calcHitProb(attacking, defending, move);

        // roll percentile to hit; roll must be below probability to hit
        float percentile = (rand() % 100) * 0.01;
        bool moveHit = hitProb > percentile;

        // debug message
        println_debug("Random percentile: " << percentile);
        println_debug("Move hit: " << (moveHit ? "True" : "False"));
        println_debug("");

        return moveHit;
    }
}
Example #24
0
bool Pawn::isValid(Move m) {
    Delta d=m.getDelta();
    if (d==possibleMoves[0] or d==possibleMoves[2] or d==possibleMoves[3]) return true;
    if (!(this->hasMoved()) and d==possibleMoves[1]) return true;
    // can't move of two if it's not the first move
    else return false;
}
Example #25
0
void Battle::addText(Pokemon a_user, Move a_move) {
	D3DXCOLOR tempcolor = D3DXCOLOR(0.0f,0.0f,0.0f,1.0f);
	swprintf_s(charactertempthingy[curtextincrement], a_user.getName());
	battletext[curtextincrement].text = charactertempthingy[curtextincrement];// User's name
	battletext[curtextincrement].rec.top = 375;
	battletext[curtextincrement].rec.bottom = 450;
	battletext[curtextincrement].rec.left = 300;
	battletext[curtextincrement].rec.right = 500;
	battletext[curtextincrement].textColor = tempcolor;
	++curtextincrement;
	swprintf_s(charactertempthingy[curtextincrement], L"used");
	battletext[curtextincrement].text = charactertempthingy[curtextincrement];// Used
	battletext[curtextincrement].rec.top = 375;
	battletext[curtextincrement].rec.bottom = 450;
	battletext[curtextincrement].rec.left = 425;
	battletext[curtextincrement].rec.right = 625;
	battletext[curtextincrement].textColor = tempcolor;
	++curtextincrement;
	swprintf_s(charactertempthingy[curtextincrement], a_move.getName());
	battletext[curtextincrement].text = charactertempthingy[curtextincrement];// User's move's name
	battletext[curtextincrement].rec.top = 375;
	battletext[curtextincrement].rec.bottom = 450;
	battletext[curtextincrement].rec.left = 575;
	battletext[curtextincrement].rec.right = 775;
	battletext[curtextincrement].textColor = tempcolor;
	++curtextincrement;
}
Example #26
0
const char* hm5move(const char* path, int max_depth, int time_limit)
{
    Board b;
    while (*path) {
	Move m(path);
	path += 4;
	if (*path == '/')
	    path++;
	if (m == INVALID_MOVE || !b.is_valid_move(m))
	    return "XXXX invalid move ";
	b.do_move(m);
    }
    visited_nodes = 0;
    Move m = com_move(&b, max_depth, time_limit);
    return m.fourcc();
}
Example #27
0
void RemotePlayer::MoveAdapter::moveMade(Move move) {
	if (this->player->getPiece() != move.getPiece())  return;
	try {
		this->player->client->makeMove(move);
		this->player->fireMoveMade(move);
	} catch (...) { }
}
Example #28
0
/*-----------------------------------------------------------------------------*/
void Notation::Continue(bool del_stop)
{
	if (is_result(this->move_current_->move_type()))
	{
		// 結果の場合
		Move* move = this->move_current_;
		
		this->Prev(1); // 1手戻す

		if (del_stop && move->move_type() == MoveType::STOP)
		{
			// ブランチ削除 ※結果にブランチがぶら下がっていることはないからこれでok
			this->DeleteBranch(-1);
		}
	}
}
Example #29
0
void MoveList::readDemoStartBlock(BitStream *stream)
{
   stream->read(&mLastMoveAck);
   stream->read(&mLastClientMove);
   stream->read(&mFirstMoveIndex);

   U32 size;
   Move mv;
   stream->read(&size);
   mMoveVec.clear();
   while(size--)
   {
      mv.unpack(stream);
      pushMove(mv);
   }
}
void Game::updateGameBackMoveQueen(const Move &m) {
  const Move m1 = m.makeBackMove();
  queenLeaveField(m1);
  SET_PIECE(m.m_from, m.m_piece);
  setNonCapturingQueen(m1);
  m.m_piece->m_pinnedState = getPinnedState(m.m_from);
}