Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pingouins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Felton Samuel
pingouins
Commits
cf46f5e9
Commit
cf46f5e9
authored
9 years ago
by
Bariatti Francesco
Browse files
Options
Downloads
Patches
Plain Diff
Updated tools
parent
434c94c4
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/board2Bitboard.py
+43
-0
43 additions, 0 deletions
tools/board2Bitboard.py
tools/gui.py
+9
-9
9 additions, 9 deletions
tools/gui.py
with
52 additions
and
9 deletions
tools/board2Bitboard.py
0 → 100755
+
43
−
0
View file @
cf46f5e9
#!/usr/bin/env python3
#-*- encoding: utf-8 -*-
def
board2Bitboard
(
board
):
"""
Convert a real board to its bitboard representation.
:param board: a sequence of 1, 2 and 3 that tells how many fish are in every tile. A character that isn
'
t 1, 2 or 3 is considered water. Newlines, pipes and spaces are ignored.
:type board: str
"""
board
=
board
.
replace
(
"
\n
"
,
""
)
board
=
board
.
replace
(
"
|
"
,
""
)
board
=
board
.
replace
(
"
"
,
""
)
print
(
board
)
if
len
(
board
)
!=
60
:
print
(
"
Warning: board is not 60 char long!
"
)
ones
=
0
twos
=
0
threes
=
0
for
c
in
board
:
if
c
==
'
1
'
:
ones
|=
1
elif
c
==
'
2
'
:
twos
|=
1
elif
c
==
'
3
'
:
threes
|=
1
ones
=
ones
<<
1
twos
=
twos
<<
1
threes
=
threes
<<
1
ones
=
ones
>>
1
twos
=
twos
>>
1
threes
=
threes
>>
1
return
(
ones
,
twos
,
threes
)
if
__name__
==
"
__main__
"
:
try
:
while
True
:
board
=
input
(
"
Enter board:
"
)
ones
,
twos
,
threes
=
board2Bitboard
(
board
)
print
(
"
one_fish: {}
\n
two_fish: {}
\n
three_fish: {}
"
.
format
(
ones
,
twos
,
threes
))
except
KeyboardInterrupt
:
print
(
"
\n
May the fish be with you.
"
)
This diff is collapsed.
Click to expand it.
tools/gui.py
+
9
−
9
View file @
cf46f5e9
...
@@ -13,24 +13,22 @@ if __name__ == "__main__":
...
@@ -13,24 +13,22 @@ if __name__ == "__main__":
#READ
#READ
readloop
=
True
readloop
=
True
comments
=
[]
comments
=
[]
json_data
=
[]
json_data
=
""
brackets_count
=
0
brackets_count
=
0
while
readloop
:
while
readloop
:
line
=
program
.
stdout
.
readline
()
line
=
program
.
stdout
.
readline
()
#
print(line)
print
(
line
)
if
line
.
startswith
(
"
{
"
):
#in json or entering json
line
=
line
.
replace
(
"
Red move:
"
,
""
)
brackets_count
+=
1
line
=
line
.
replace
(
"
Blue move:
"
,
""
)
if
brackets_count
>
0
:
#We are in the middle of json data
if
line
.
startswith
(
"
{
"
):
#Reading json
json_data
.
append
(
line
)
json_data
=
line
else
:
else
:
comments
.
append
(
line
)
comments
.
append
(
line
)
if
line
.
startswith
(
"
}
"
):
brackets_count
-=
1
if
line
==
"
\n
"
:
if
line
==
"
\n
"
:
readloop
=
False
readloop
=
False
#PRINT STATE
#PRINT STATE
print
(
"
Comments: {}
"
.
format
(
''
.
join
(
comments
)))
print
(
"
Comments: {}
"
.
format
(
''
.
join
(
comments
)))
state
=
json
.
loads
(
''
.
join
(
json_data
)
)
state
=
json
.
loads
(
json_data
)
drawState
.
drawBitboard
(
state
[
"
bitboards
"
][
"
onefish
"
],
state
[
"
bitboards
"
][
"
twofish
"
],
state
[
"
bitboards
"
][
"
threefish
"
])
drawState
.
drawBitboard
(
state
[
"
bitboards
"
][
"
onefish
"
],
state
[
"
bitboards
"
][
"
twofish
"
],
state
[
"
bitboards
"
][
"
threefish
"
])
print
(
"
Red penguins (Red score: {}, Total moves: {} [0..{}])
"
.
format
(
state
[
"
score
"
][
"
red
"
],
state
[
"
nb_moves
"
][
"
red
"
],
state
[
"
nb_moves
"
][
"
red
"
]
-
1
))
print
(
"
Red penguins (Red score: {}, Total moves: {} [0..{}])
"
.
format
(
state
[
"
score
"
][
"
red
"
],
state
[
"
nb_moves
"
][
"
red
"
],
state
[
"
nb_moves
"
][
"
red
"
]
-
1
))
for
i
in
range
(
4
):
for
i
in
range
(
4
):
...
@@ -45,6 +43,8 @@ if __name__ == "__main__":
...
@@ -45,6 +43,8 @@ if __name__ == "__main__":
move
=
input
(
"
Enter Blue move:
"
)
move
=
input
(
"
Enter Blue move:
"
)
program
.
stdin
.
write
(
move
+
"
\n
"
)
program
.
stdin
.
write
(
move
+
"
\n
"
)
program
.
stdin
.
flush
()
program
.
stdin
.
flush
()
except
BrokenPipeError
:
print
(
"
Game end
"
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
print
(
"
\n
May the fish be with you.
"
)
print
(
"
\n
May the fish be with you.
"
)
finally
:
finally
:
...
...
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