Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Classification of Text-Background Color Combination
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s183927
Classification of Text-Background Color Combination
Commits
7158e4b2
Commit
7158e4b2
authored
Dec 20, 2018
by
s183927
Browse files
Options
Downloads
Patches
Plain Diff
Improved UI, added data save function, missing data import function
parent
8555ef42
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
GamerAI.py
+35
-11
35 additions, 11 deletions
GamerAI.py
down.png
+0
-0
0 additions, 0 deletions
down.png
up.png
+0
-0
0 additions, 0 deletions
up.png
with
35 additions
and
11 deletions
GamerAI.py
+
35
−
11
View file @
7158e4b2
import
pygame
import
os
import
numpy
as
np
from
random
import
randint
from
sklearn.neighbors
import
NearestNeighbors
...
...
@@ -17,6 +18,8 @@ clock.tick(60)
# keyboard pictures and predictor
leftPic
=
pygame
.
image
.
load
(
'
left.png
'
)
rightPic
=
pygame
.
image
.
load
(
'
right.png
'
)
downPic
=
pygame
.
image
.
load
(
'
down.png
'
)
upPic
=
pygame
.
image
.
load
(
'
up.png
'
)
predPic
=
pygame
.
image
.
load
(
'
predictor.png
'
)
# make the pygame window
...
...
@@ -30,7 +33,7 @@ smallfont = pygame.font.SysFont('comicsansms', 25)
mediumfont
=
pygame
.
font
.
SysFont
(
'
comicsansms
'
,
50
)
largefont
=
pygame
.
font
.
SysFont
(
'
comicsansms
'
,
80
)
# matrixes of color, index 0 should be deleted
# matrixes of color, index 0 should be deleted
, used if trained anew
points
=
np
.
array
([[
0
,
0
,
0
]])
white
=
np
.
array
([[
0
,
0
,
0
]])
black
=
np
.
array
([[
0
,
0
,
0
]])
...
...
@@ -57,25 +60,31 @@ while True:
display
.
fill
((
123
,
123
,
123
))
# draw color boxes
pygame
.
draw
.
rect
(
display
,
color
,
[(
width
-
200
)
/
4
,
300
,
200
,
200
])
pygame
.
draw
.
rect
(
display
,
color
,
[(
width
-
200
)
/
1.25
,
300
,
200
,
200
])
pygame
.
draw
.
rect
(
display
,
color
,
[
width
/
3
-
200
/
2
,
300
,
200
,
200
])
pygame
.
draw
.
rect
(
display
,
color
,
[
width
/
1.5
-
200
/
2
,
300
,
200
,
200
])
pygame
.
draw
.
rect
(
display
,
(
37
,
37
,
37
),
[
width
/
3
-
220
/
2
-
4
,
75
,
220
,
40
])
pygame
.
draw
.
rect
(
display
,
(
37
,
37
,
37
),
[
width
/
1.5
-
245
/
2
-
4
,
75
,
245
,
40
])
# blit pics of arrows
display
.
blit
(
leftPic
,
((
width
-
200
)
/
4
+
70
,
512
))
display
.
blit
(
rightPic
,
((
width
-
200
)
/
1.25
+
70
,
512
))
display
.
blit
(
leftPic
,
(
width
/
3
-
63
/
2
,
512
))
display
.
blit
(
rightPic
,
(
width
/
1.5
-
63
/
2
,
512
))
display
.
blit
(
downPic
,
((
width
/
3
-
63
/
2
),
125
))
display
.
blit
(
upPic
,
((
width
/
1.5
-
63
/
2
),
125
))
# text
text
(
'
text
'
,
(
255
,
255
,
255
),
largefont
,
(
width
-
200
)
/
4
+
20
,
330
)
text
(
'
text
'
,
(
0
,
0
,
0
),
largefont
,
(
width
-
200
)
/
1.25
+
20
,
330
)
text
(
'
bazinga
'
,
(
255
,
2
,
255
),
largefont
,
75
,
25
)
text
(
'
text
'
,
(
255
,
255
,
255
),
largefont
,
width
/
3
-
200
/
2
+
20
,
330
)
text
(
'
text
'
,
(
0
,
0
,
0
),
largefont
,
width
/
1.5
-
200
/
2
+
20
,
330
)
text
(
'
save training data
'
,
(
255
,
255
,
255
),
smallfont
,
width
/
3
-
216
/
2
,
75
)
text
(
'
import training data
'
,
(
255
,
255
,
255
),
smallfont
,
width
/
1.5
-
241
/
2
,
75
)
# make prediction, display prediction above color box
y
=
np
.
reshape
(
color
,
(
-
1
,
3
))
if
len
(
points
)
>
1
:
if
nn
(
points
,
y
)
in
white
:
display
.
blit
(
predPic
,
(
(
width
-
200
)
/
4
+
60
,
200
))
display
.
blit
(
predPic
,
(
width
/
3
-
80
/
2
,
200
))
elif
nn
(
points
,
y
)
in
black
:
display
.
blit
(
predPic
,
(
(
width
-
200
)
/
1.
2
5
+
60
,
200
))
display
.
blit
(
predPic
,
(
width
/
1.5
-
80
/
2
,
200
))
# remove [0,0,0]
if
len
(
points
)
==
2
and
np
.
array_equal
(
points
[
0
],
np
.
array
([
0
,
0
,
0
])):
...
...
@@ -103,3 +112,18 @@ while True:
black
=
np
.
vstack
((
black
,
color
))
points
=
np
.
vstack
((
points
,
color
))
loop
=
False
if
event
.
key
==
pygame
.
K_DOWN
:
try
:
os
.
remove
(
"
training.txt
"
)
except
:
pass
dataFile
=
open
(
"
training.txt
"
,
"
w
"
)
dataFile
.
write
(
str
(
points
)
+
"
\n
"
)
dataFile
.
write
(
str
(
white
)
+
"
\n
"
)
dataFile
.
write
((
str
(
black
)
+
"
\n
"
))
dataFile
.
close
()
if
event
.
key
==
pygame
.
K_UP
:
try
:
pass
except
:
pass
\ No newline at end of file
This diff is collapsed.
Click to expand it.
down.png
0 → 100644
+
0
−
0
View file @
7158e4b2
17.3 KiB
This diff is collapsed.
Click to expand it.
up.png
0 → 100644
+
0
−
0
View file @
7158e4b2
17.3 KiB
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment