Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
supercomputer_lab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
supercomputer_lab
Commits
41fe5b36
Commit
41fe5b36
authored
Jun 24, 2012
by
Gaurav Kukreja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sequential Minimax for Abalone
Signed-off-by:
Gaurav Kukreja
<
mailme.gaurav@gmail.com
>
parent
94304c6d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
3 deletions
+161
-3
Makefile
mpi-assign5/Makefile
+3
-2
player.cpp
mpi-assign5/player.cpp
+1
-1
search-minimax.cpp
mpi-assign5/search-minimax.cpp
+157
-0
No files found.
mpi-assign5/Makefile
View file @
41fe5b36
...
...
@@ -5,7 +5,7 @@
#CXX = g++
# Use this for the Intel C++ compiler ("icc" is only the C version)
CXX
=
icpc
CXX
=
g++
# Use this for MPI
#CXX = mpiCC
...
...
@@ -23,7 +23,7 @@ LDFLAGS=
LIB_OBJS
=
move.o board.o network.o search.o eval.o
SEARCH_OBJS
=
$(LIB_OBJS)
search-abid.o search-onelevel.o
SEARCH_OBJS
=
$(LIB_OBJS)
search-abid.o search-onelevel.o
search-minimax.o
all
:
player start referee
...
...
@@ -52,3 +52,4 @@ start.o: start.cpp board.cpp move.cpp
referee.o
:
referee.cpp board.cpp move.cpp
search-onelevel.o
:
search.h board.h eval.h
search-abid.o
:
search.h board.h
search-minimax.o
:
search.h board.h eval.h
mpi-assign5/player.cpp
View file @
41fe5b36
...
...
@@ -30,7 +30,7 @@ Evaluator ev;
int
myColor
=
Board
::
color1
;
/* Which search strategy to use? */
int
strategyNo
=
0
;
int
strategyNo
=
2
;
/* Max search depth */
int
maxDepth
=
0
;
...
...
mpi-assign5/search-minimax.cpp
0 → 100644
View file @
41fe5b36
/*
* Very simple example strategy:
* Search all possible positions reachable via one move,
* and return the move leading to best position
*
* (c) 2006, Josef Weidendorfer
*/
#include <stdio.h>
#include "search.h"
#include "board.h"
#include "eval.h"
#define pretty_print(name, val) printf("%s = %d: %s: %s: %d\n", name, val, __FILE__,__FUNCTION__,__LINE__);
/**
* To create your own search strategy:
* - copy this file into another one,
* - change the class name one the name given in constructor,
* - adjust clone() to return an instance of your class
* - adjust last line of this file to create a global instance
* of your class
* - adjust the Makefile to include your class in SEARCH_OBJS
* - implement searchBestMove()
*
* Advises for implementation of searchBestMove():
* - call foundBestMove() when finding a best move since search start
* - call finishedNode() when finishing evaluation of a tree node
* - Use _maxDepth for strength level (maximal level searched in tree)
*/
class
MinimaxStrategy
:
public
SearchStrategy
{
public
:
// Defines the name of the strategy
MinimaxStrategy
()
:
SearchStrategy
(
"MINIMAX"
)
{}
// Factory method: just return a new instance of this class
SearchStrategy
*
clone
()
{
return
new
MinimaxStrategy
();
}
private
:
/**
* Implementation of the strategy.
*/
void
searchBestMove
();
int
minimax
();
};
int
current_depth
=
0
;
#define MAX_DEPTH 3
int
MinimaxStrategy
::
minimax
()
{
Move
m
;
MoveList
list
;
int
maxEval
,
minEval
;
int
eval
;
int
sign
;
if
(
current_depth
==
MAX_DEPTH
)
return
evaluate
();
maxEval
=
-
17000
;
minEval
=
17000
;
generateMoves
(
list
);
if
(
evaluate
()
==
16000
)
{
if
(
current_depth
==
0
)
finishedNode
(
0
,
0
);
pretty_print
(
"current_depth"
,
current_depth
);
return
((
current_depth
%
2
)
==
0
)
?
-
16000
:
16000
;
}
while
(
list
.
getNext
(
m
))
{
if
(
current_depth
<
MAX_DEPTH
)
{
current_depth
++
;
playMove
(
m
);
eval
=
minimax
();
takeBack
();
current_depth
--
;
}
if
((
MAX_DEPTH
-
current_depth
+
1
)
%
2
==
0
)
{
if
(
eval
>
maxEval
)
{
maxEval
=
eval
;
if
(
current_depth
==
0
)
{
pretty_print
(
"Eval"
,
eval
);
foundBestMove
(
0
,
m
,
eval
);
}
}
}
else
{
if
(
eval
<
minEval
)
{
minEval
=
eval
;
if
(
current_depth
==
0
)
{
pretty_print
(
"Eval2"
,
eval
);
foundBestMove
(
0
,
m
,
eval
);
}
}
}
}
if
(
current_depth
==
0
)
finishedNode
(
0
,
0
);
if
((
MAX_DEPTH
-
current_depth
+
1
)
%
2
==
0
)
return
maxEval
;
else
return
minEval
;
}
void
MinimaxStrategy
::
searchBestMove
()
{
// KUKU : Here we have to implement the minimax strategy
// Minimax strategy tries to minimize the maximum possible outcome of opponent.
// At each turn, we check for each move the max positive outcome for opponent.
// We choose the move for which the max is least.
// To check this, we look at more than one levels in the Game Tree.
// we try to maximize bestEvaluation
/* int bestEval = minEvaluation();
int eval;
Move m;
MoveList list;
// generate list of allowed moves, put them into <list>
generateMoves(list);
// loop over all moves
while(list.getNext(m)) {
// draw move, evalute, and restore position
playMove(m);
eval = evaluate();
takeBack();
if (eval > bestEval) {
bestEval = eval;
foundBestMove(0, m, eval);
}
}
finishedNode(0,0);
*/
minimax
();
}
// register ourselve as a search strategy
MinimaxStrategy
minimaxStrategy
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment