Beispiel #1
0
void
InGameModel::update_path()
{
  if (has_valid_move() || !has_valid_goal()) {
    dep_puzzle_->clear_path();
  } else {
    // If required, look for a path
    if (has_goal_changed() || has_player_moved()) {
      assert(goal_i_ != -1);
      assert(goal_j_ != -1);

      dep_puzzle_->clear_path();

      assert(current_move_index_ < (int) dep_puzzle_->moves().size());
      int move_type = dep_puzzle_->moves()[current_move_index_].type();
    
      dep_path_finder_.find_path(dep_puzzle_,
				 dep_puzzle_->get_player_i(),
				 dep_puzzle_->get_player_j(),
				 goal_i_,
				 goal_j_,
				 move_type);

      last_goal_i_ = goal_i_;
      last_goal_j_ = goal_j_;

      last_player_i_ = dep_puzzle_->get_player_i();
      last_player_j_ = dep_puzzle_->get_player_j();

    }
  }
}
//executes move if it is valid. Returns false and does not update Alex_Ayerdi otherwise
//Makes computer make its move and returns the computer's move in row, and col
bool Alex_Ayerdi::play_square(int &row, int &col){
	int blackplayer = 1;
	int whiteplayer = -1;

	if (row == 0 && col == 0)
	{
		setPlayer(blackplayer);
	}
	else
	{
		if (player == blackplayer)
			play_square(row, col, whiteplayer);
		if (player == whiteplayer)
			play_square(row, col, blackplayer);
	}

	//generate your own move
	if(full_board())
	{
		row = -1;
		col = -1;
		return false;
	}
	else 
	{
		cout << toString() << "..." << endl;
		vector<int> cell;
		this->reset_tries();
		if (!has_valid_move(player))
		{
			cout << "Alex_Ayerdi must pass." << endl;
			row = -1;
			col = -1;
			return false;
		}
		else 
		{
			int alphaStart = -INFINITY;
			int betaStart = INFINITY;

			//generate move
			make_minimax_alphabeta_cpu_move(this, player, cell, alphaStart, betaStart);
			//play move
			if (!play_square(cell[0], cell[1], player))
			{
				row = -1;
				col = -1;
				return false;
			}
			
			//pass to opposing player
			row = cell[0];
			col = cell[1];
		}
			
		cout << toString();
	}

	return true;
}