Reversi Game with AI Implementation in MATLAB: Project Report

Verified

Added on  2023/04/25

|4
|826
|462
Project
AI Summary
This project details the design and implementation of an Othello (Reversi) game with AI using MATLAB. The game incorporates C code integrated into MATLAB functions via MEX files for performance optimization. The game offers two modes: Human vs. AI and AI vs. AI. The AI utilizes a heuristic algorithm, including a minimax decision with alpha-beta pruning, to determine moves. The heuristic function considers factors like score, corner pieces, and mobility, implemented in C for speed. The project features a GUI with sidebar options for game settings, loading/saving game states, and adjusting AI thinking time. The solution includes compiling and running instructions, demonstrating the game's functionality and AI strategy. The game board is represented as a matrix and the AI uses a simple heuristic-based optimization search. The program allows the user to select to play as black or white.
Document Page
Running head: Othello or revrsi Game Implementation in matlab 1
Reversi game with AI Implementation in MATLAB
Executive Summary
MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment and
proprietary programming language developed by MathWorks. ... The MATLAB application is
built around the MATLAB scripting language. Common usage of the MATLAB application
involves using the Command Window as an interactive mathematical shell or executing text files
containing MATLAB code. MATLAB can call functions and subroutines written in the
programming languages C or Fortran. A wrapper function is created allowing MATLAB data
types to be passed and returned. MEX files are the dynamically loadable object files created by
compiling such functions.[27] Since 2014 increasing two-way interfacing with Python was being
added.
In this assignment we did with C language . In this project we design and develop and Reversi
game with AI using MATLAB. We build C code into MATLAB functions .This game is simple
game and we design this code using AI .We design and develop Reversi game two option AI vs
AI ,Human vs AI . In this game we develop the strategy for computer using efficient Heuristic
algorithm implementation. Othello allows user to play Othello game in MATLAB GUI against a
simple AI. The AI for this game only is designed only to find the most swapping possible at its
turn. It does not try to anticipate the next possible turn or try to capture tiles at the board edge,
which makes it fairly easy to beat.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Othello or revrsi Game Implementation in matlab 2
MALAB
Game Description
The boards are represented as matrices where 0 represents an empty spot, -1: a black
token, and 1: a white token. Initially, finding all valid moves was implemented in MATLAB
using image dilation techniques using a 3x3 ones matrix. However, profiling showed that this
was too slow. So finding all valid moves was implemented in C code. This was done using an
array of function pointers representing the eight rays emanating from a candidate move position.
Candidate locations are empty and a neighbor of an enemy token. Candidates that produced a
nonzero number of flips are returned as a vector of actions. Their corresponding resultant boards
are also returned as a 3D matrix of valid next-boards.
The AI itself is implemented using a minimax decision with alpha-beta pruning. The heuristic is
calculated based on a weighted sum of score, number of corners, and mobility. The heuristic is
zero-sum, so Min's benefits are subtracted from Max's benefits etc. The heuristic function is
meant to be calculated quickly as well, so this was another function I implemented in C and built
back into MATLAB using MEX.
A simple one-player othello board-game program. Players control the white piece while the
computer AI controls the black. The AI uses a simple heuristic-based optimization search. For
simplicity, it only searches up to one move ahead.
Reversi, also known as Othello, is a game in which reversible white/black chips are placed on a
grid. The goal is to have the most pieces once the board is full (i.e. there are no more legal
moves). A move, to be legal, must flip at least one opponent's chip by flanking it. "Flanking"
occurs by surrounding a line of opposing chips with two of your own. It can occur on straight
lines and diagonals.
Document Page
Othello or revrsi Game Implementation in matlab 3
Compile and Run the code
You can do this in the MATLAB command window:
mex getAllValid.c
mex utility_c.c
Then you can run the main program by running:
main.m
There are two option
1. "Human vs AI"
2. "AI vs AI"
First option if we select "Human vs AI", we have the choice between playing as black or
white.
Second option there is no need to choice
Document Page
Othello or revrsi Game Implementation in matlab 4
In this game we design a sidebar gives access to certain game settings and options
therefore we can load game states or save the current game state. The game timeline can be
altered by moving the iteration slider or changing the iteration number text box. The allotted for
the AI to think can also be changed here. By default, the AI is given 1 second to think, but you
can change that at any point in the game. The current score of the game is also displayed on the
sidebar. We can then test the game by changing the move iteration slider or text box.
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]