First working version of CSS generation. Bot not that good yet. Haha.
This commit is contained in:
55
tictactoe.py
55
tictactoe.py
@@ -1,49 +1,24 @@
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from bot import get_sudoku_moves
|
||||
|
||||
|
||||
def write_html(html_file):
|
||||
html_top = [
|
||||
'<html>',
|
||||
'<head>',
|
||||
' <title>Tic Tac Toe CSS</title>',
|
||||
' <link rel="stylesheet" type="text/css" href="tictactoe.css">',
|
||||
'</head>',
|
||||
'<body>',
|
||||
' <div class="tic-tac-toe">']
|
||||
|
||||
html_bottom = [
|
||||
' </div>',
|
||||
'</body>',
|
||||
'</html>']
|
||||
tepl_input = ' <input class="field-{field} ' \
|
||||
'row-{row} col-{col} turn-{turn}" ' \
|
||||
'id="block-{turn}-{row}-{col}" type="radio">'
|
||||
|
||||
tepl_label = ' <label class="turn-{turn}" ' \
|
||||
'for="block-{turn}-{row}-{col}"></label>'
|
||||
html_main = []
|
||||
|
||||
for turn in range(9):
|
||||
c = " <!-- turn-{} -->".format(turn)
|
||||
html_main.append(c)
|
||||
for row in range(3):
|
||||
for col in range(3):
|
||||
d = {
|
||||
"field": row * 3 + col,
|
||||
"turn": turn,
|
||||
"row": row,
|
||||
"col": col}
|
||||
input_ = tepl_input.format(**d)
|
||||
label_ = tepl_label.format(**d)
|
||||
html_main.append(input_)
|
||||
html_main.append(label_)
|
||||
html_main.append("")
|
||||
|
||||
html = html_top + html_main + html_bottom
|
||||
env = Environment(loader=FileSystemLoader("."))
|
||||
template = env.get_template('template.' + html_file)
|
||||
with open(html_file, 'w') as f:
|
||||
f.write("\n".join(html))
|
||||
f.write(template.render())
|
||||
|
||||
|
||||
def write_css(css_file):
|
||||
pass
|
||||
kwargs = {
|
||||
"turns_player": [0, 2, 4, 6, 8],
|
||||
"turns_bot": [1, 3, 5, 7],
|
||||
"moves": get_sudoku_moves(),
|
||||
}
|
||||
env = Environment(loader=FileSystemLoader("."))
|
||||
template = env.get_template('template.' + css_file)
|
||||
with open(css_file, 'w') as f:
|
||||
f.write(template.render(**kwargs))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user