Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
KSnakeDuel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Games
KSnakeDuel
Commits
33c79b95
Commit
33c79b95
authored
Sep 18, 2020
by
Friedrich W. H. Kossebau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port away from deprecated KRandomSequence
GIT_SILENT
parent
3a1453ca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
29 deletions
+28
-29
intelligence.cpp
intelligence.cpp
+26
-27
intelligence.h
intelligence.h
+2
-2
No files found.
intelligence.cpp
View file @
33c79b95
...
...
@@ -29,9 +29,8 @@
#include <KgDifficulty>
Intelligence
::
Intelligence
()
:
m_random
(
QRandomGenerator
::
global
()
->
generate
())
{
m_random
.
setSeed
(
0
);
m_lookForward
=
15
;
}
...
...
@@ -99,7 +98,7 @@ void Intelligence::changeDirection(int playerNr,int dis_right,int dis_left)
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
{
// change direction
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
(
100
*
dis_left
)
/
(
dis_left
+
dis_right
))
if
(
m_random
.
bounded
(
100
)
<=
(
100
*
dis_left
)
/
(
dis_left
+
dis_right
))
{
if
(
dis_left
!=
1
)
// turn to the left
...
...
@@ -313,13 +312,13 @@ void Intelligence::think(int playerNr)
// opponent is to the right and we have the chance to block the way
if
(
opSideDis
>
0
&&
opSideDis
<
opForwardDis
&&
opSideDis
<
dis_right
&&
opForwardDis
<
m_lookForward
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
1
]);
// turn right
}
// opponent is to the left and we have the chance to block the way
else
if
(
opSideDis
<
0
&&
-
opSideDis
<
opForwardDis
&&
-
opSideDis
<
dis_left
&&
opForwardDis
<
m_lookForward
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
0
]);
// turn left
}
// if we can do nothing, go forward
...
...
@@ -328,7 +327,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -338,7 +337,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
// end if(opMovesOppositeDir)
...
...
@@ -350,13 +349,13 @@ void Intelligence::think(int playerNr)
// opponent is to the right and we have the chance to block the way
if
(
opSideDis
>
0
&&
opSideDis
<
-
opForwardDis
&&
opSideDis
<
dis_right
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
1
]);
// turn right
}
// opponent is to the left and we have the chance to block the way
else
if
(
opSideDis
<
0
&&
-
opSideDis
<
-
opForwardDis
&&
-
opSideDis
<
dis_left
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
||
dis_forward
==
1
)
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
0
]);
// turn left
}
// if we can do nothing, go forward
...
...
@@ -365,7 +364,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -375,7 +374,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
// end if(opMovesSameDir)
...
...
@@ -389,7 +388,7 @@ void Intelligence::think(int playerNr)
{
if
(
opForwardDis
<
m_lookForward
&&
dis_left
>
m_lookForward
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
else
if
(
dis_forward
<
m_lookForward
)
...
...
@@ -397,7 +396,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -406,7 +405,7 @@ void Intelligence::think(int playerNr)
{
if
(
opForwardDis
<
m_lookForward
&&
dis_right
>
m_lookForward
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
1
]);
// turn right
}
else
if
(
dis_forward
<
m_lookForward
)
...
...
@@ -414,7 +413,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -423,7 +422,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -433,7 +432,7 @@ void Intelligence::think(int playerNr)
// opponent is right from us and we already blocked him
if
(
opSideDis
>
0
&&
opForwardDis
<
m_lookForward
&&
opSideDis
<
dis_right
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
else
if
(
dis_forward
<
m_lookForward
)
...
...
@@ -441,7 +440,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -456,7 +455,7 @@ void Intelligence::think(int playerNr)
{
if
(
opForwardDis
<
m_lookForward
&&
dis_right
>
m_lookForward
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
else
if
(
dis_forward
<
m_lookForward
)
...
...
@@ -464,7 +463,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -473,7 +472,7 @@ void Intelligence::think(int playerNr)
{
if
(
opForwardDis
<
m_lookForward
&&
dis_left
>
m_lookForward
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
0
]);
// m_turn left
}
else
if
(
dis_forward
<
m_lookForward
)
...
...
@@ -481,7 +480,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
...
...
@@ -491,7 +490,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -501,7 +500,7 @@ void Intelligence::think(int playerNr)
// opponent is left from us and we already blocked him
if
(
opSideDis
<
0
&&
opForwardDis
<
m_lookForward
&&
-
opSideDis
<
dis_left
)
{
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
<=
doPercentage
/
2
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
else
if
(
dis_forward
<
m_lookForward
)
...
...
@@ -509,7 +508,7 @@ void Intelligence::think(int playerNr)
dis_forward
=
100
-
100
/
dis_forward
;
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
1
)
changeDirection
(
playerNr
,
dis_right
,
dis_left
);
}
}
...
...
@@ -609,9 +608,9 @@ void Intelligence::think(int playerNr)
index
[
1
]
+=
flags
[
5
];
}
if
(
!
(
dis_left
==
1
&&
dis_right
==
1
))
{
if
(
(
int
)
m_random
.
getLong
(
100
)
>=
dis_forward
||
dis_forward
==
0
)
{
if
(
m_random
.
bounded
(
100
)
>=
dis_forward
||
dis_forward
==
0
)
{
// change direction
if
(
(
int
)
m_random
.
getLong
(
100
)
<=
(
100
*
dis_left
)
/
(
dis_left
+
dis_right
))
{
if
(
m_random
.
bounded
(
100
)
<=
(
100
*
dis_left
)
/
(
dis_left
+
dis_right
))
{
if
(
dis_left
!=
1
)
// turn to the left
m_tron
->
getPlayer
(
playerNr
)
->
setDirection
(
sides
[
0
]);
...
...
intelligence.h
View file @
33c79b95
...
...
@@ -25,7 +25,7 @@
#define INTELLIGENCE_H
#include <math.h>
#include <
krandomsequence.h
>
#include <
QRandomGenerator
>
class
Tron
;
...
...
@@ -47,7 +47,7 @@ class Intelligence
Tron
*
m_tron
;
/** The random sequence generator **/
KRandomSequence
m_random
;
QRandomGenerator
m_random
;
/** determines level of computerplayer */
int
m_lookForward
;
};
...
...
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