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
0d794a39
Commit
0d794a39
authored
Dec 22, 2018
by
s183927
Browse files
Options
Downloads
Patches
Plain Diff
You can now save and import saved data
parent
7158e4b2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
GamerAI.py
+51
-8
51 additions, 8 deletions
GamerAI.py
with
51 additions
and
8 deletions
GamerAI.py
+
51
−
8
View file @
0d794a39
import
pygame
import
os
import
time
import
numpy
as
np
import
pandas
as
pd
from
random
import
randint
from
sklearn.neighbors
import
NearestNeighbors
...
...
@@ -112,18 +114,59 @@ while True:
black
=
np
.
vstack
((
black
,
color
))
points
=
np
.
vstack
((
points
,
color
))
loop
=
False
# check if button presses are down or up, if they are, they save or import data
if
event
.
key
==
pygame
.
K_DOWN
:
# check if previous files exist
try
:
os
.
remove
(
"
training.txt
"
)
os
.
remove
(
"
points.txt
"
)
os
.
remove
(
"
white.txt
"
)
os
.
remove
(
"
black.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
()
# make a file for the points matrix
pointsFile
=
open
(
"
points.txt
"
,
"
w
"
)
for
n
in
points
:
for
i
in
range
(
len
(
n
)):
if
i
==
len
(
n
)
-
1
:
pointsFile
.
write
(
str
(
n
[
i
]))
else
:
pointsFile
.
write
(
str
(
n
[
i
])
+
"
"
)
pointsFile
.
write
(
"
\n
"
)
pointsFile
.
close
()
# make a file for the white matrix
whiteFile
=
open
(
"
white.txt
"
,
"
w
"
)
for
n
in
white
:
for
i
in
range
(
len
(
n
)):
if
i
==
len
(
n
)
-
1
:
whiteFile
.
write
(
str
(
n
[
i
]))
else
:
whiteFile
.
write
(
str
(
n
[
i
])
+
"
"
)
whiteFile
.
write
(
"
\n
"
)
whiteFile
.
close
()
# make a file for the black matrix
blackFile
=
open
(
"
black.txt
"
,
"
w
"
)
for
n
in
black
:
for
i
in
range
(
len
(
n
)):
if
i
==
len
(
n
)
-
1
:
blackFile
.
write
(
str
(
n
[
i
]))
else
:
blackFile
.
write
(
str
(
n
[
i
])
+
"
"
)
blackFile
.
write
(
"
\n
"
)
blackFile
.
close
()
text
(
"
Data successfully saved to files
"
,
(
255
,
255
,
255
),
smallfont
,
10
,
10
)
pygame
.
display
.
update
()
if
event
.
key
==
pygame
.
K_UP
:
try
:
pass
points
=
np
.
loadtxt
(
"
points.txt
"
)
white
=
np
.
loadtxt
(
"
white.txt
"
)
black
=
np
.
loadtxt
(
"
black.txt
"
)
text
(
"
Data successfully imported
"
,
(
255
,
255
,
255
),
smallfont
,
10
,
10
)
pygame
.
display
.
update
()
except
:
pass
\ No newline at end of file
text
(
"
Data failed to be imported
"
,
(
255
,
255
,
255
),
mediumfont
,
10
,
10
)
pygame
.
display
.
update
()
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