Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Pengfei Chen committed Oct 3, 2023
1 parent fc5653e commit aaab410
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
58 changes: 30 additions & 28 deletions unitary/examples/quantum_chinese_chess/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,75 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unitary.alpha as alpha
from enums import (
SquareState,
GameState,
Color,
Type,
Language
)
from enums import SquareState, GameState, Color, Type, Language
from piece import Piece
from colorama import Fore, Back, Style


class Board:
def __init__(self):
self.load_fen()
self.king_locations = {"e0", "e9"}
self.current_state = GameState.CONTINUE

def load_fen(self, fen: str = "RHEAKAEHR/9/1C5C1/P1P1P1P1P/9/9/p1p1p1p1p/1c5c1/9/rheakaehr"):
def load_fen(
self, fen: str = "RHEAKAEHR/9/1C5C1/P1P1P1P1P/9/9/p1p1p1p1p/1c5c1/9/rheakaehr"
):
chess_board = {}
row_index = 9
for row in fen.split("/"):
col = ord('a')
col = ord("a")
for char in row:
# Add empty board pieces.
if "1" <= char <= "9":
for i in range(int(char)):
name = chr(col) + "%i" % row_index
chess_board[name] = Piece(name, SquareState.EMPTY, Type.EMPTY, Color.NA)
chess_board[name] = Piece(
name, SquareState.EMPTY, Type.EMPTY, Color.NA
)
col += 1
# Add occupied board pieces.
else:
name = chr(col) + "%i" % row_index
piece_type = Type.type_of(char)
color = Color.RED if char.isupper() else Color.BLACK
chess_board[name] = Piece(name, SquareState.OCCUPIED, piece_type, color)
chess_board[name] = Piece(
name, SquareState.OCCUPIED, piece_type, color
)
col += 1
row_index -= 1
self.board = alpha.QuantumWorld(chess_board.values())

def print(self, lang: Language = Language.EN):
num_rows = 10
board_string = "";
board_string += " ";
board_string = ""
board_string += " "
# Print the top line of col letters.
for col in 'abcdefghi':
board_string += " %c"%col
board_string += "\n";
for col in "abcdefghi":
board_string += " %c" % col
board_string += "\n"
for row in range(num_rows):
# Print the row index on the left.
board_string += "%d "%row;
for col in 'abcdefghi':
piece = self.board[col + "%d" % row]
board_string += piece.symbol(True, lang)
if lang == Language.EN or piece.type_ == Type.EMPTY:
board_string += " "
# Print the row index on the right.
board_string += " %d\n"%row
# Print the row index on the left.
board_string += "%d " % row
for col in "abcdefghi":
piece = self.board[col + "%d" % row]
board_string += piece.symbol(True, lang)
if lang == Language.EN or piece.type_ == Type.EMPTY:
board_string += " "
# Print the row index on the right.
board_string += " %d\n" % row
board_string += " "
# Print the bottom line of col letters.
for col in 'abcdefghi':
board_string += " %c"%col
for col in "abcdefghi":
board_string += " %c" % col
print(board_string)

def flying_general(self) -> bool:
print("### flying general rule check to be implemented")
return False


board = Board()
board.print()

board.print(Language.ZH)
board.print(Language.ZH)
68 changes: 35 additions & 33 deletions unitary/examples/quantum_chinese_chess/print_board.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@

def print_board():
num_rows = 10
board_string = "";
board_string += " ";
for col in 'abcdefghi':
board_string += " %c"%col
board_string += "\n";
board_string = ""
board_string += " "
for col in "abcdefghi":
board_string += " %c" % col
board_string += "\n"
for row in range(num_rows):
board_string += "%d "%row;
for col in 'abcdefghi':
# board_string += "车"
# board_string += ". "
board_string += "R "
# board_string += PieceAt(col, row).symbol()
# Piece p = pieceAt(col, row);
# if p == null:
# board_string += " .";
# else:
# switch (p.rank) {
# case ROOK: board_string += p.isRed ? " R" : " r"; break;
# case KNIGHT: board_string += p.isRed ? " N" : " n"; break;
# case BISHOP: board_string += p.isRed ? " B" : " b"; break;
# case GUARD: board_string += p.isRed ? " G" : " g"; break;
# case KING: board_string += p.isRed ? " K" : " k"; break;
# case CANNON: board_string += p.isRed ? " C" : " c"; break;
# case PAWN: board_string += p.isRed ? " P" : " p"; break;
# }
board_string += " %d\n"%row
board_string += "%d " % row
for col in "abcdefghi":
# board_string += "车"
# board_string += ". "
board_string += "R "
# board_string += PieceAt(col, row).symbol()
# Piece p = pieceAt(col, row);
# if p == null:
# board_string += " .";
# else:
# switch (p.rank) {
# case ROOK: board_string += p.isRed ? " R" : " r"; break;
# case KNIGHT: board_string += p.isRed ? " N" : " n"; break;
# case BISHOP: board_string += p.isRed ? " B" : " b"; break;
# case GUARD: board_string += p.isRed ? " G" : " g"; break;
# case KING: board_string += p.isRed ? " K" : " k"; break;
# case CANNON: board_string += p.isRed ? " C" : " c"; break;
# case PAWN: board_string += p.isRed ? " P" : " p"; break;
# }
board_string += " %d\n" % row
board_string += " "
for col in 'abcdefghi':
board_string += " %c"%col
for col in "abcdefghi":
board_string += " %c" % col
print(board_string)


print_board()

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')

print(Fore.RED + "some red text")
from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')

print(Fore.RED + "some red text")
print(Back.GREEN + "and with a green background")
print(Style.DIM + "and in dim text")
print(Style.RESET_ALL)
print('back to normal now')
print("back to normal now")

0 comments on commit aaab410

Please sign in to comment.