0% found this document useful (0 votes)
30 views4 pages

othello_4

othello desc

Uploaded by

doordashtemp743
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

othello_4

othello desc

Uploaded by

doordashtemp743
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Othello Lab 4 — 2000 Games against Random

AI - Fall 2024

Now that you have an Othello infrastructure in place, you are ready to do something useful with it. In
particular, you can imagine your script playing a game against another script by way of a moderator
script whose job it is to query each of the two scripts in turn asking them: given this board and a token
(corresponding to their side), what move should be made? At this point, the queried script should
respond with a preferred move.

For this to be practical, time has to be taken into account. In particular, it is often the case that when you
look at a situation (any situation), you might amend your initial impression with a subsequent view. It
is this way with game playing, too, in that if your script has more time, it might be able to come up with
a better course of action (move to play). Therefore, what constitutes a move declaration, when called
from the command line, is the final integer that a script prints before it either terminates voluntarily or
gets cut off.

Othello Lab 4: Play 2000 games against Random, getting the largest percent of tokens.

In particular, the moderator (the Othello 4 grader) will pit your script against Random in 2000 games,
where your script will play alternating games as x and 0, with the grader accumulating the following two
numbers at the end of each game: total number of tokens on your script’s side and the total number of
tokens on the board. You are looking to maximize this ratio.

The Othello 4 lab is an extension of your Othello 3 lab. The extensions are:
(A) define a quickMove() function which can be directly called by the grader
(B) display the preferred move (quickMove()) when called from the command line
(C) accept a condensed game transcript as a command line argument.
(D) accept an s flag on the command line, suppressing all but the first and last snapshot from printing

When called from the command line, your Othello 4 receives the same input as your Othello 3 lab (with
the addition of condensed move transcripts and print suppression, described below). After the Othello
3 part of your script has run, if the game is not over, it should print out a preferred move according to:

print (f"My preferred move is: {mvPref}").

Where mvPref is your preferred move from among all the possible moves. Please see the description
of quickMove(), below, for details on how the preferred move could be determined.

When the Othello 4 grader is running as a moderator, it is the moderator’s responsibility to make each
indicated move, to determine whether one side or another must pass, and also when the game is over. In
this mode, your script will always receive a board and a token where a move is possible, and the
responsibility of your script is to print or return a valid move, depending on how it is called.

© Csaba Gabor p 1/3 11 Dec ‘24


The grader will first test to ensure that you have maintained the functionality of Othello 3, along with
the extension to condensed transcripts and print suppression. These features are for debugging purposes.
After this, the grader as moderator will run a tournament pitting your script against Random in 2000
games. As command line invocations of your script would not be sufficiently time efficient, the moder-
ator uses a different technique for this lab. It will import your script, and then directly call a function
you must define, quickMove(), to get the preferred move. In this mode, the moderator will not call
your script from the command line and there is nothing to be printed, only the preferred move should be
returned. Therefore, your code must sense when it is being called from the command line. Your code
should have the following structure:

. Othello 3 code here ...

def quickMove(brd, tkn):


possibleMoves = findMoves(brd, tkn)
# return the preferred move from among the possible moves

def main():
. Othello 3 script to run if called from cmd line ...

if game is not over (ie. there is a possible move) :


mypref = quickMove (mostRecentBoard, tknToPlay)
print (f"The preferred move is: {mvPref}")

. set global lookup tables ...


if name == ' main_': main()

# Jo Student, pd. 9, 2025

A trivial way to finish quickMove() is by doing: return [*possibleMoves |[@], but this would
be quite poor as it is equivalent to what Random does.

When the moderator nee grader is running a tournament, it will call quickMove() on the order of
2000*30 times. Printing in this function is a bad idea when submitting to the grader. At the end of the
tournament, the moderator will print out a condensed transcript of the three worst games. A particularly
grievous example is: 19344352371110 9262951453059465544233340202125241842. Each
move occupies two bytes and single digit moves have an underscore as the first character (note the _9
in the example). Condensed transcripts may have negative numbers, which should be ignored. The only
one you will see in this lab is a -1, indicating a pass. Your script must be able to handle a condensed
transcript being handed to it in place of a move.

In addition, the inclusion of an s or S on the command line says that all snapshots that are not the first
and the last ones should be suppressed from printing. This is because for some debugging you are not
interested in the (presumed correct) intermediate states, but you do want to know the resulting situation
after certain moves.

© Csaba Gabor p 2/3 11 Dec ‘24


Thus, your code is being used in two ways. The moderator uses quickMove() for efficiency (with no
printing on the part of your script), and command line usage is primarily for debugging (ie. Othello 3
with a post script of a preferred move after the final board). In both cases, the code ends up calling
quickMove(). quickMove() must be fast as your script gets .3 seconds per game, and as long as your
quickMove() is not recursive you should be OK.

It turns out that analyzing an Othello board is a non-trivial task, and there is no uniform rule of thumb.
Strategies such as the obvious ‘make the move giving you the most number of tokens’ may not actually
work in your favor. The below describes some possible strategies.

Othello strategies

You may wish to consider implementing some form of the strategies below or craft your own preferred
move. You may also research this topic on the internet. You may share ideas with your colleagues, but
sharing your code, as always, is an integrity violation, as is using another person’s code.

1) If you can play to a corner, then play to a corner. => ~ 59%

2) If you can play to a safe edge position (one that can’t be converted), then do so. => ~ 69%

3) If you can avoid playing next to a corner that isn’t yours, then don’t => ~ 74%

Other strategy concepts include mobility and stability. Places where you may read about other strategy
ideas include:

http://radagast.se/othello/Help/strategy.html

https://bonaludo.com/2017/01/04/how-to-win-at-othello-part-1-strategy-basics-stable-discs-and-
mobility/

https://www.ultraboardgames.com/othello/tips.php

and

http://samsoft.org.uk/reversi/strategy htm

The current grading on this lab, where the ratio is your tokens vs. total tokens, is defined by the
piecewise function:
81% ratio => 100% grade
71% => 88%
52% => 50%

© Csaba Gabor p 3/3 11 Dec ‘24

You might also like