Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
What's new
2
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Projects
Groups
Snippets
Register
Sign in
Toggle navigation
Menu
Open sidebar
AlaskaLinuxUser
picoEngine
Commits
a7d24092
Commit
a7d24092
authored
Feb 20, 2019
by
alaskalinuxuser
Browse files
ply moves enabled.
parent
ce79782b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Engine.cpp
View file @
a7d24092
...
...
@@ -26,6 +26,7 @@ string inputString = "";
bool
runProgram
=
true
;
bool
styleRandom
=
false
;
Board
board
;
int
chosenPly
=
3
;
Moves
movePick
;
string
engineMove
=
""
;
...
...
@@ -73,7 +74,7 @@ void inputGo()
{
cout
<<
"Going...."
<<
endl
;
engineMove
=
""
;
engineMove
=
movePick
.
bestMove
(
board
.
moveBoard
(),
board
.
getTurn
(),
styleRandom
,
board
.
getIsPassent
(),
board
.
getEnPassent
(),
1
);
engineMove
=
movePick
.
bestMove
(
board
.
moveBoard
(),
board
.
getTurn
(),
styleRandom
,
board
.
getIsPassent
(),
board
.
getEnPassent
(),
chosenPly
);
cout
<<
"bestmove "
+
engineMove
<<
endl
;
}
void
inputQuit
()
...
...
Moves.cpp
View file @
a7d24092
...
...
@@ -1633,20 +1633,12 @@ string Moves::available(string boardPositions, bool whoseTurn, bool isPass, char
*/
}
string
Moves
::
bestMove
(
string
boardPositions
,
bool
whoseTurn
,
bool
styleRandom
,
bool
isPass
,
char
enPass
,
int
plyMoves
){
string
Moves
::
plyMove
(
string
boardPositions
,
bool
whoseTurn
,
bool
isPass
,
char
enPass
,
int
plyMoves
){
plyMoves
--
;
string
candidateList
=
Moves
::
available
(
boardPositions
,
whoseTurn
,
isPass
,
enPass
);
string
chosenMove
=
""
;
int
currentEval
=
0
;
if
(
candidateList
.
size
()
>
0
){
if
(
styleRandom
)
{
// Make a random move.
srand
((
int
)
time
(
0
)
+
candidateList
.
size
());
int
r
=
(
rand
()
%
(
candidateList
.
size
()
/
5
));
for
(
int
a
=
0
;
a
<
4
;
a
++
)
{
chosenMove
+=
candidateList
[(
5
*
r
)
+
a
];
}
// End random move.
}
else
{
// Not random, so make educated moves.
currentEval
=
evaluations
.
getEval
(
boardPositions
);
cout
<<
"Current eval: "
<<
" time "
<<
(
int
)
time
(
0
)
<<
" eval "
<<
currentEval
<<
endl
;
int
moveEval
=
0
;
...
...
@@ -1667,7 +1659,6 @@ string Moves::bestMove(string boardPositions, bool whoseTurn, bool styleRandom,
boardPositions
[
first
]
=
'-'
;
moveEval
=
evaluations
.
getEval
(
boardPositions
);
cout
<<
"Move eval: "
<<
chosenMove
<<
" eval "
<<
moveEval
<<
" places "
<<
boardPositions
<<
endl
;
plyMoves
--
;
if
(
whoseTurn
){
// White's turn, higher is better.
if
(
moveEval
>
bestEval
)
{
...
...
@@ -1687,10 +1678,76 @@ string Moves::bestMove(string boardPositions, bool whoseTurn, bool styleRandom,
bestEval
=
moveEval
;
}
}
try
{
if
(
plyMoves
>
0
){
whoseTurn
=
!
whoseTurn
;
string
nextMove
=
plyMove
(
boardPositions
,
whoseTurn
,
isPass
,
enPass
,
plyMoves
);
whoseTurn
=
!
whoseTurn
;
int
third
=
((
nextMove
.
at
(
0
)
-
'a'
+
1
)
+
(((
nextMove
.
at
(
1
)
-
'1'
)
*
8
)
-
1
));
int
fourth
=
((
nextMove
.
at
(
2
)
-
'a'
+
1
)
+
(((
nextMove
.
at
(
3
)
-
'1'
)
*
8
)
-
1
));
char
thirdPieceHolder
=
boardPositions
[
third
];
char
fourthPieceHolder
=
boardPositions
[
fourth
];
boardPositions
[
fourth
]
=
boardPositions
[
third
];
boardPositions
[
third
]
=
'-'
;
int
newMoveEval
=
evaluations
.
getEval
(
boardPositions
);
cout
<<
"Move eval: "
<<
chosenMove
<<
" eval "
<<
moveEval
<<
" places "
<<
boardPositions
<<
endl
;
if
(
whoseTurn
){
// White's turn, higher is better.
if
(
newMoveEval
>
bestEval
)
{
chosenMove
=
proposedMove
;
bestEval
=
newMoveEval
;
}
else
if
(
newMoveEval
==
bestEval
&&
(
int
)
time
(
0
)
%
2
==
0
)
{
chosenMove
=
proposedMove
;
bestEval
=
newMoveEval
;
}
}
else
{
// Black's turn, lower is better.
if
(
newMoveEval
<
bestEval
)
{
chosenMove
=
proposedMove
;
bestEval
=
newMoveEval
;
}
else
if
(
newMoveEval
==
bestEval
&&
(
int
)
time
(
0
)
%
2
==
0
)
{
chosenMove
=
proposedMove
;
bestEval
=
newMoveEval
;
}
}
boardPositions
[
third
]
=
thirdPieceHolder
;
boardPositions
[
fourth
]
=
fourthPieceHolder
;
}
}
catch
(...)
{
cout
<<
" Exception "
<<
endl
;
}
// End try/catch block
boardPositions
[
first
]
=
firstPieceHolder
;
boardPositions
[
second
]
=
secondPieceHolder
;
}
// End candidate list moves.
}
else
{
// candidate list is 0.... game over.
}
return
chosenMove
;
}
string
Moves
::
bestMove
(
string
boardPositions
,
bool
whoseTurn
,
bool
styleRandom
,
bool
isPass
,
char
enPass
,
int
plyMoves
){
string
candidateList
=
Moves
::
available
(
boardPositions
,
whoseTurn
,
isPass
,
enPass
);
string
chosenMove
=
""
;
if
(
candidateList
.
size
()
>
0
){
if
(
styleRandom
)
{
// Make a random move.
srand
((
int
)
time
(
0
)
+
candidateList
.
size
());
int
r
=
(
rand
()
%
(
candidateList
.
size
()
/
5
));
for
(
int
a
=
0
;
a
<
4
;
a
++
)
{
chosenMove
+=
candidateList
[(
5
*
r
)
+
a
];
}
// End random move.
}
else
{
// Not random, so make educated moves.
try
{
chosenMove
=
plyMove
(
boardPositions
,
whoseTurn
,
isPass
,
enPass
,
plyMoves
);
}
catch
(...)
{
cout
<<
" Exception "
<<
endl
;
}
// End try/catch block
}
// End not random.
if
(
chosenMove
==
""
)
{
// Chosen move is still blank, and list is not 0, that is wrong, so pick a random move.
chosenMove
=
bestMove
(
boardPositions
,
whoseTurn
,
true
,
isPass
,
enPass
,
plyMoves
);}
}
// End candidates list.
return
chosenMove
;
}
Moves.h
View file @
a7d24092
...
...
@@ -28,9 +28,12 @@ public:
// All available moves.
string
available
(
string
boardPositions
,
bool
whoseTurn
,
bool
isPass
,
char
enPass
);
//
Best move
.
//
Choose a move, random or weighted
.
string
bestMove
(
string
boardPositions
,
bool
whoseTurn
,
bool
styleRandom
,
bool
isPass
,
char
enPass
,
int
plyMoves
);
// Weighted move, considering ply.
string
plyMove
(
string
boardPositions
,
bool
whoseTurn
,
bool
isPass
,
char
enPass
,
int
plyMoves
);
// Is the king safe?
bool
isKingSafe
(
string
boardPositions
,
bool
whoseTurn
);
...
...
Moves.o
View file @
a7d24092
No preview for this file type
engine.o
View file @
a7d24092
No preview for this file type
moves.o
View file @
a7d24092
No preview for this file type
picoEngine
View file @
a7d24092
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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