Question: In C++ , I need help to implementing my AlphaBetaPlayer. I am playing a checkers game and implementing an AI player using alpha-beta search. I

In C++ , I need help to implementing my AlphaBetaPlayer. I am playing a checkers game and implementing an AI player using alpha-beta search. I am stuck on one part I already have code which implements the checkers board and also computes all the legal moves for any given state. I have areas that I need to implement an evaluation function and then Negamax with alpha-beta prunning but am unsure how. Any help or example code would be great the areas are marked in my source code below.

ALPHABETAPLAYER.CPP

#include "AlphaBetaPlayer.hpp"

#include

#include

bool AlphaBetaPlayer::SelectMove(const Checkers::State s,

const Checkers::PlayerColor player,

Move & bestMove)

{

auto score = Negamax(s, player, bestMove, -INFINITY, INFINITY, m_depth);

std::cout << "player = " << player << " bestScore = " << score << " bestMove = ";

for(int i = 0; i < (int) bestMove.m_ids.size(); ++i)

std::cout << "["

<< GetCheckers()->RowFromId(bestMove.m_ids[i]) << ","

<< GetCheckers()->ColFromId(bestMove.m_ids[i]) << "]";

std::cout << std::endl;

return true;

}

double AlphaBetaPlayer::Evaluate(const Checkers::State s)

{

double score = 0;

***//add your implementation

return score;

}

double AlphaBetaPlayer::Negamax(const Checkers::State s,

const Checkers::PlayerColor player,

Move & superBest,

double alpha,

double beta,

int depth)

{

***//add your implementation

return 0.0;

}

ALPHABETAPLAYER.hpp

#ifndef AI__AlphaBetaPlayer_hpp_

#define AI__AlphaBetaPlayer_hpp_

#include "Player.hpp"

#include "Definitions.hpp"

#include

//This is the class that you should implement

class AlphaBetaPlayer : public Player

{

public:

AlphaBetaPlayer(void) : Player(),

m_depth(3)

{

}

virtual ~AlphaBetaPlayer(void)

{

}

//Get the depth for the alpha-beta search

virtual int GetDepth(void) const

{

return m_depth;

}

//Set the depth for the alpha-beta search

virtual void SetDepth(const int d)

{

m_depth = d;

}

//This function will call the Negamax function

//to compute the best move the player

//should make

virtual bool SelectMove(const Checkers::State s,

const Checkers::PlayerColor player,

Move & bestMove);

protected:

*** //Implement negamax

//Function should return the score

//It should also compute the best move

virtual double Negamax(const Checkers::State s,

const Checkers::PlayerColor player,

Move & bestMove,

double alpha,

double beta,

int depth);

*** //Your evaluation function

virtual double Evaluate(const Checkers::State s);

//Depth for the alpha-beta search

int m_depth;

};

#endif

This is example of suedo code for negamax with alpha-beta pruning from wiki, it can be very useful cause we are trying to implement soemthing like this.

function negamax(node, depth, ?, ?, color) if depth = 0 or node is a terminal node return color * the heuristic value of node childNodes := GenerateMoves(node) childNodes := OrderMoves(childNodes) bestValue := ?? foreach child in childNodes v := ?negamax(child, depth ? 1, ??, ??, ?color) bestValue := max( bestValue, v ) ? := max( ?, v ) if ? ? ? break return bestValue

instead of best value I want to return score and compute best move!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!