Git Product home page Git Product logo

othello-reversi's Introduction

Othello-Reversi Game

Using alpha-beta prunning algorithm

Alpha–beta pruning is a search algorithm that seeks to decrease the number of nodes that are evaluated by the minimax algorithm in its search tree. It stops evaluating a move when at least one possibility has been found that proves the move to be worse than a previously examined move. Such moves need not be evaluated further. When applied to a standard minimax tree, it returns the same move as minimax would, but prunes away branches that cannot possibly influence the final decision.

You can see the implementation of the algorithm in C++ here, and the visualization in WinForms C#.

Algorithm

The algorithm is implemented in 'Othello' project and computed in Othello.dll library. Main part of algorithm:

void othello_state::state::minimax(othello_state::state& current_state, 
    int& chosen_score, 
    int& pi, int& pj, 
    bool minmax, 
    bool alpha_beta, 
    int black_best, 
    int white_best, 
    int depth,
    bool current_step) {
	if (depth == 0)
	{
		chosen_score = current_state.heuristic(current_step);
	}
	else {
		std::vector<state*> steps = current_state.generate_steps();
		if (steps.size() == 0)
		{
			state* st = current_state.empty_step();
			minimax(*st, chosen_score, pi, pj, !minmax, alpha_beta, black_best, white_best, depth - 1, current_step);
			delete st;
		}
		else {
			int best_score = minmax * INT16_MAX +!minmax * INT16_MIN;
			int x = pi, y = pj;
			for (size_t i = 0; i < steps.size(); i++)
			{
				int score  = chosen_score;
				int xt, yt;
				minimax(*steps[i], score, xt, yt, !minmax, alpha_beta, black_best, white_best, depth - 1,current_step);
				if (alpha_beta)
				{
					// if is step of white disks
					if (minmax && score < white_best)
					{
						if (score < black_best)
						{
							break;
						}
						else {
							white_best = score;
						}
					}
					// if is step of black disks
					if (!minmax && score > black_best)
					{
						if (score > white_best)
						{
							break;
						}
						else {
							black_best = score;
						}
					}
				}
				if (better(score, best_score, minmax))
				{
					best_score = score;
					x = steps[i]->_i;
					y = steps[i]->_j;
				}

			}
			for (size_t i = 0; i < steps.size(); i++)
			{
				delete steps[i];
			}
			chosen_score = best_score;
			pi = x;
			pj = y;

		}

	}
}

Visual Part

Visual part is implemented by WinForms C# framework. The current available moves are marked in dark pink

game

othello-reversi's People

Contributors

aram-osipyan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.