diff --git a/diagram.py b/diagram.py index e907087..56289e4 100644 --- a/diagram.py +++ b/diagram.py @@ -35,6 +35,9 @@ def build(self) -> SvgDiagram: text_args = dict(text_anchor='middle', font_family='Raleway', font_size=round(0.55*square_size)) + corner_text_args = dict(text_anchor='middle', + font_family='Raleway', + font_size=round(0.375*square_size)) margins = (0, 0) for line in lines[8:]: command, body = line.split(':', maxsplit=1) @@ -45,6 +48,12 @@ def build(self) -> SvgDiagram: extra_elements.add(extra_elements.text(fields[0], (x, y), **text_args)) + elif command == 'corner text': + x = round(x0 + (float(fields[1]) - 0.344) * square_size, 1) + y = round(y0 - (float(fields[2]) + 0.445) * square_size, 1) + extra_elements.add(extra_elements.text(fields[0], + (x, y), + **corner_text_args)) elif command == 'rect': x1, y1, x2, y2 = [float(field) for field in fields] left = round(15 + (x1-1)*square_size, 1) diff --git a/docs/images/new_rules/diagram1.png b/docs/images/new_rules/diagram1.png index 00adc3b..9594bc9 100644 Binary files a/docs/images/new_rules/diagram1.png and b/docs/images/new_rules/diagram1.png differ diff --git a/docs/images/new_rules/diagram2.png b/docs/images/new_rules/diagram2.png index c588a3b..f4b0c7e 100644 Binary files a/docs/images/new_rules/diagram2.png and b/docs/images/new_rules/diagram2.png differ diff --git a/docs/images/new_rules/diagram3.png b/docs/images/new_rules/diagram3.png index b620be2..f5b2886 100644 Binary files a/docs/images/new_rules/diagram3.png and b/docs/images/new_rules/diagram3.png differ diff --git a/docs/images/new_rules/diagram4.png b/docs/images/new_rules/diagram4.png index 88c4840..1d6af34 100644 Binary files a/docs/images/new_rules/diagram4.png and b/docs/images/new_rules/diagram4.png differ diff --git a/docs/images/new_rules/diagram5.png b/docs/images/new_rules/diagram5.png deleted file mode 100644 index f5b2886..0000000 Binary files a/docs/images/new_rules/diagram5.png and /dev/null differ diff --git a/docs/images/new_rules/diagram6.png b/docs/images/new_rules/diagram6.png deleted file mode 100644 index 1d6af34..0000000 Binary files a/docs/images/new_rules/diagram6.png and /dev/null differ diff --git a/docs/new_rules.md b/docs/new_rules.md index e6ae774..78c1dbc 100644 --- a/docs/new_rules.md +++ b/docs/new_rules.md @@ -7,93 +7,84 @@ These are new games that aren't ready yet. You can try them out and let me know what you think. ## Table of Contents -* [Manna Chess][manna-chess] adds random power ups to chess. (2 - players, chess set, checkers set, and 2 dice) +* [Adrenaline Chess][adrenaline-chess] adds power ups to chess. (2 + players, chess set, and checkers set) * [Cloak and Dagger Chess][cloak-and-dagger-chess] is a game where you disguise your chess pieces as checkers, then try to identify your opponent's pieces. (2 players, chess set, checkers set, pen, and tape) -[manna-chess]: #manna-chess +[adrenaline-chess]: #adrenaline-chess [cloak-and-dagger-chess]: #cloak-and-dagger-chess # New Games These games are in early development or playtesting. The rules might get more filled out or change based on feedback from players. -## Manna Chess -The god of war drops manna after every capture, and manna can make any piece a -king. This game adds a little chaos to chess, and accelerates the end game. +## Adrenaline Chess +What if taking your opponent's piece frightened the others so much that they +became more aggressive? Every time you take a piece, you have to choose one of +the remaining pieces to get an adrenaline rush, and adrenaline can make any +piece a king. This game adds a little chaos to chess, and accelerates the end +game. ### Equipment -A standard chess set, a standard set of 24 checkers, and two dice. The checkers +A standard chess set and a standard set of 24 checkers. The checkers must be stackable, and you must be able to stack a chess piece on top of the checkers. Coins or poker chips would also work, as long as they fit inside the chess board squares. ### Setup Set up the chess pieces in the standard start position, and randomly choose who -will play white. Place the 24 checkers and the dice beside the board. +will play white. Place the checkers beside the board. ### Play -All the regular chess rules apply, plus you get to drop manna after one of your -pieces is captured. If one or more of your pieces were just captured, start your -turn by pointing to one of the four corners of the board. Then roll two dice to -decide which file (column) the manna will land on. The corner you're pointing to -is 3, then count up across the board to the number you rolled. Rolls of 2, 11, -or 12 miss the board, and you get no manna. Then roll the two dice again to -decide which rank (row) the manna will land on. Again, you're pointing at 3, -and count up across the board to 10. If manna lands on the board, add a checker -to that square. The colour of the checker doesn't matter. If that square has a -chess piece or other checkers on it, add the new checker to the stack. - -In the following example, white just captured a pawn with the bishop, so now -black points to the bottom-left corner and rolls a 7 and a 6. Counting from the -left, the 7 puts it on the e file. Counting from the bottom, the 6 puts it on -e4. +All the regular chess rules apply, plus you must give an adrenaline rush after +captures. If you captured one or more pieces, end your turn by placing a +checker under one of your opponent's remaining pieces. The colour of the +checker doesn't matter, and you may stack multiple checkers under a piece. -![Diagram](images/new_rules/diagram1.png) - -Checkers or stacks of checkers without a chess piece on them are neutral manna -pieces that can be captured by either player. When you capture them, stack your -capturing piece on top. You cannot jump over manna, except with a knight. When -you capture an opponent's piece, you keep any manna they were carrying. +In the following example, white just captured a pawn with the bishop, and +finishes the turn by adding a checker under the pawn at h7. -Captured manna are carried with the chess piece on top when you move the chess -piece. If one of your pieces has manna after you move it, you may eat one of -those manna and make an extra king move with that piece. Eat a manna by -removing it from the stack and putting back in the supply beside the board. If -the piece still has manna, you may continue making king moves until you run out. +![Diagram](images/new_rules/diagram1.png) -For example, in this position, the pawns at e3 and e5 cannot capture the manna -at e4. However, the white pawn at d3 can. Once it captures the manna, it could -immediately eat it and capture the pawn at e5 with a king's move. That would be -a poor choice, though, because the pawn at d6 could capture it back. +To move a piece with checkers under it, you must make a regular move for that +piece, and bring the checkers along. Then you may use up one of the checkers +under that piece to make an extra move like a king. Remove a checker from the +stack, and move the rest one space in any direction. If that piece still has +checkers under it, you may continue making extra king moves until the piece +runs out of checkers. + +The extra moves may capture pieces, but you only ever add one checker per turn. +When you capture an opponent's piece, your capturing piece keeps any adrenaline +the captured piece had, and may immediately use the adrenaline. + +For example, here is a strange checkmate that uses white's adrenaline to +threaten the white king. Black has just captured a pawn, and has spent the last +few turns pumping a trapped bishop full of adrenaline. Adding a third checker +to the stack at c1 would seem to make the bishop a threat to the black queen, +but it must make a regular move before it can start using the adrenaline. White +has been forced to keep the king retreating, and hasn't been able to move the +pawns that would free the bishop. The black queen on the other hand, will be +able to capture the bishop on the next turn, and then use those three checkers +to capture the king at f2, possibly capturing the pawn at d2 along the way. +Moving the king to e1 or e3 would still be in range for the queen. e2 would be +a direct capture by the queen, f1 and f3 could be captured by the queen or the +black bishop. g3 might give a glimmer of hope, until you notice that the black +pawn at h5 has a checker. It is checkmate. ![Diagram](images/new_rules/diagram2.png) -White decides to capture the manna, but not eat it. - -![Diagram](images/new_rules/diagram3.png) +After castling, you may use both the king and the rook for extra moves, if they +both have checkers. You may capture a pawn en passant on the second rank at the +usual square after a regular move of two squares. You may not capture en passant +at a square that the pawn left using an extra move, and you may not use an extra +move to capture en passant. A pawn that moves to the back rank immediately +promotes, and may continue making king moves if it still has checkers. ### Winning -Win by capturing the king, either with a regular move or with a manna move. You -must call check or check mate if you can, but it's possible for a lucky manna -drop to allow a capture when you couldn't call check mate on the previous turn. - -### Manna Strategy -Because 7 is the most common roll with two dice, you have some control over -where the manna will drop when you choose which corner to count from. For -example, if you chose the bottom-left corner 1000 times, here are how many times -you would expect the manna to land in each square: - -![Diagram](images/new_rules/diagram4.png) - -You would also expect to miss the board 210 times, so you will add a piece of -manna roughly 8 out of 10 times you roll. - -You can see that the most likely square is the centre square opposite the corner -you start counting in, so check which squares you occupy or can attack before -you roll for manna. +Win by checkmate, as in regular chess, but you may use extra moves to threaten +the king. # Broken Games These ideas seemed promising, but didn't work at the table. Maybe I'll come back @@ -111,7 +102,7 @@ write the numbers 1 to 8 on checkers for each player. Put the black checkers on black's back row and the light checkers on white's back row. Finally, write two grids like this to secretly record your pieces and deduce your opponent's: -![Diagram](images/new_rules/diagram5.png) +![Diagram](images/new_rules/diagram3.png) Obviously, you don't have to put the pieces in their standard starting positions, but you do have to have a standard set of pieces. (You can't give @@ -127,7 +118,7 @@ opponent learns which of your combinations are impossible. Here's one possible way to fill in your grid at the start of the game: -![Diagram](images/new_rules/diagram6.png) +![Diagram](images/new_rules/diagram4.png) At the start of your turn, you may guess the identity of one of your opponent's checkers. If you guess correctly, you may make a bonus move after your regular diff --git a/publish_rules.py b/publish_rules.py index 4acc891..e809e83 100644 --- a/publish_rules.py +++ b/publish_rules.py @@ -66,6 +66,7 @@ def __init__(self, self.diagram_differ = DiagramDiffer() self.diagram_differ.tolerance = 10 self.is_disabled = is_disabled + self.unused_images = set(images_folder.glob('diagram*.png')) def add_diagram(self, diagram: Diagram) -> Path: if self.is_disabled: @@ -77,6 +78,7 @@ def add_diagram(self, diagram: Diagram) -> Path: file_name = f'diagram{self.diagram_count}.png' target_path = self.images_folder / file_name relative_path = target_path.relative_to(self.target_folder) + self.unused_images.remove(target_path) try: old_image = LivePillowImage(Image.open(target_path)) self.diagram_differ.compare(old_image, image) @@ -87,6 +89,10 @@ def add_diagram(self, diagram: Diagram) -> Path: image.write_png(target_path) return relative_path + def remove_unused_images(self) -> None: + for image_path in self.unused_images: + image_path.unlink() + class RulesDocTemplate(SimpleDocTemplate): def __init__(self, @@ -347,6 +353,7 @@ def main(): first_bullet, bulleted_list_style, numbered_list_style) + diagram_writer.remove_unused_images() if not args.booklet: story.append(cc_drawing) story.append(Paragraph( diff --git a/raw_rules/new_rules.md b/raw_rules/new_rules.md index 7831243..e539cf4 100644 --- a/raw_rules/new_rules.md +++ b/raw_rules/new_rules.md @@ -11,36 +11,31 @@ know what you think. These games are in early development or playtesting. The rules might get more filled out or change based on feedback from players. -## Manna Chess -The god of war drops manna after every capture, and manna can make any piece a -king. This game adds a little chaos to chess, and accelerates the end game. +## Adrenaline Chess +What if taking your opponent's piece frightened the others so much that they +became more aggressive? Every time you take a piece, you have to choose one of +the remaining pieces to get an adrenaline rush, and adrenaline can make any +piece a king. This game adds a little chaos to chess, and accelerates the end +game. ### Equipment -A standard chess set, a standard set of 24 checkers, and two dice. The checkers +A standard chess set and a standard set of 24 checkers. The checkers must be stackable, and you must be able to stack a chess piece on top of the checkers. Coins or poker chips would also work, as long as they fit inside the chess board squares. ### Setup Set up the chess pieces in the standard start position, and randomly choose who -will play white. Place the 24 checkers and the dice beside the board. +will play white. Place the checkers beside the board. ### Play -All the regular chess rules apply, plus you get to drop manna after one of your -pieces is captured. If one or more of your pieces were just captured, start your -turn by pointing to one of the four corners of the board. Then roll two dice to -decide which file (column) the manna will land on. The corner you're pointing to -is 3, then count up across the board to the number you rolled. Rolls of 2, 11, -or 12 miss the board, and you get no manna. Then roll the two dice again to -decide which rank (row) the manna will land on. Again, you're pointing at 3, -and count up across the board to 10. If manna lands on the board, add a checker -to that square. The colour of the checker doesn't matter. If that square has a -chess piece or other checkers on it, add the new checker to the stack. +All the regular chess rules apply, plus you must give an adrenaline rush after +captures. If you captured one or more pieces, end your turn by placing a +checker under one of your opponent's remaining pieces. The colour of the +checker doesn't matter, and you may stack multiple checkers under a piece. -In the following example, white just captured a pawn with the bishop, so now -black points to the bottom-left corner and rolls a 7 and a 6. Counting from the -left, the 7 puts it on the e file. Counting from the bottom, the 6 puts it on -e4. +In the following example, white just captured a pawn with the bishop, and +finishes the turn by adding a checker under the pawn at h7. r n b q k b n r . p p p p p p p @@ -51,137 +46,59 @@ e4. P P P P . P P P R N B Q K . N R arrow: f1, a6, white - arrow: e4, e4, gray - -Checkers or stacks of checkers without a chess piece on them are neutral manna -pieces that can be captured by either player. When you capture them, stack your -capturing piece on top. You cannot jump over manna, except with a knight. When -you capture an opponent's piece, you keep any manna they were carrying. - -Captured manna are carried with the chess piece on top when you move the chess -piece. If one of your pieces has manna after you move it, you may eat one of -those manna and make an extra king move with that piece. Eat a manna by -removing it from the stack and putting back in the supply beside the board. If -the piece still has manna, you may continue making king moves until you run out. - -For example, in this position, the pawns at e3 and e5 cannot capture the manna -at e4. However, the white pawn at d3 can. Once it captures the manna, it could -immediately eat it and capture the pawn at e5 with a king's move. That would be -a poor choice, though, because the pawn at d6 could capture it back. - - r n b q k b n r - . p p . . p p p - B . . p . . . . + arrow: h7, h7, gray + +To move a piece with checkers under it, you must make a regular move for that +piece, and bring the checkers along. Then you may use up one of the checkers +under that piece to make an extra move like a king. Remove a checker from the +stack, and move the rest one space in any direction. If that piece still has +checkers under it, you may continue making extra king moves until the piece +runs out of checkers. + +The extra moves may capture pieces, but you only ever add one checker per turn. +When you capture an opponent's piece, your capturing piece keeps any adrenaline +the captured piece had, and may immediately use the adrenaline. + +For example, here is a strange checkmate that uses white's adrenaline to +threaten the white king. Black has just captured a pawn, and has spent the last +few turns pumping a trapped bishop full of adrenaline. Adding a third checker +to the stack at c1 would seem to make the bishop a threat to the black queen, +but it must make a regular move before it can start using the adrenaline. White +has been forced to keep the king retreating, and hasn't been able to move the +pawns that would free the bishop. The black queen on the other hand, will be +able to capture the bishop on the next turn, and then use those three checkers +to capture the king at f2, possibly capturing the pawn at d2 along the way. +Moving the king to e1 or e3 would still be in range for the queen. e2 would be +a direct capture by the queen, f1 and f3 could be captured by the queen or the +black bishop. g3 might give a glimmer of hope, until you notice that the black +pawn at h5 has a checker. It is checkmate. + + r n . . k . n r + . . . . . p p . . . . . p . . . - . . . . . . . . - . . . P P . . . - P P P . . P P P - R N B Q K . N R - arrow: e4, e4, gray - -White decides to capture the manna, but not eat it. - - r n b q k b n r - . p p . . p p p - B . . p . . . . - . . . . p . . . - . . . . P . . . - . . . . P . . . - P P P . . P P P - R N B Q K . N R - arrow: e4, e4, gray - arrow: d3, e4, white + . . . . P . . p + . p q . . . . . + P . . . . . . . + . P . P b K P P + R . B . . . Q . + arrow: g4, e2, black + arrow: c1, c1, gray + corner text: 3, 3, 1 + arrow: e5, e5, gray + arrow: e6, e6, gray + arrow: h5, h5, gray + arrow: g7, g7, gray + +After castling, you may use both the king and the rook for extra moves, if they +both have checkers. You may capture a pawn en passant on the second rank at the +usual square after a regular move of two squares. You may not capture en passant +at a square that the pawn left using an extra move, and you may not use an extra +move to capture en passant. A pawn that moves to the back rank immediately +promotes, and may continue making king moves if it still has checkers. ### Winning -Win by capturing the king, either with a regular move or with a manna move. You -must call check or check mate if you can, but it's possible for a lucky manna -drop to allow a capture when you couldn't call check mate on the previous turn. - -### Manna Strategy -Because 7 is the most common roll with two dice, you have some control over -where the manna will drop when you choose which corner to count from. For -example, if you chose the bottom-left corner 1000 times, here are how many times -you would expect the manna to land in each square: - - . . . . . . . . - . . . . . . . . - . . . . . . . . - . . . . . . . . - . . . . . . . . - . . . . . . . . - . . . . . . . . - . . . . . . . . - text: 3, 1, 1 - text: 5, 1, 2 - text: 6, 1, 3 - text: 8, 1, 4 - text: 9, 1, 5 - text: 8, 1, 6 - text: 6, 1, 7 - text: 5, 1, 8 - text: 5, 2, 1 - text: 7, 2, 2 - text: 9, 2, 3 - text: 12, 2, 4 - text: 14, 2, 5 - text: 12, 2, 6 - text: 9, 2, 7 - text: 7, 2, 8 - text: 6, 3, 1 - text: 9, 3, 2 - text: 12, 3, 3 - text: 15, 3, 4 - text: 19, 3, 5 - text: 15, 3, 6 - text: 12, 3, 7 - text: 9, 3, 8 - text: 8, 4, 1 - text: 12, 4, 2 - text: 15, 4, 3 - text: 19, 4, 4 - text: 23, 4, 5 - text: 19, 4, 6 - text: 15, 4, 7 - text: 12, 4, 8 - text: 9, 5, 1 - text: 14, 5, 2 - text: 19, 5, 3 - text: 23, 5, 4 - text: 28, 5, 5 - text: 23, 5, 6 - text: 19, 5, 7 - text: 14, 5, 8 - text: 8, 6, 1 - text: 12, 6, 2 - text: 15, 6, 3 - text: 19, 6, 4 - text: 23, 6, 5 - text: 19, 6, 6 - text: 15, 6, 7 - text: 12, 6, 8 - text: 6, 7, 1 - text: 9, 7, 2 - text: 12, 7, 3 - text: 15, 7, 4 - text: 19, 7, 5 - text: 15, 7, 6 - text: 12, 7, 7 - text: 9, 7, 8 - text: 5, 8, 1 - text: 7, 8, 2 - text: 9, 8, 3 - text: 12, 8, 4 - text: 14, 8, 5 - text: 12, 8, 6 - text: 9, 8, 7 - text: 7, 8, 8 - -You would also expect to miss the board 210 times, so you will add a piece of -manna roughly 8 out of 10 times you roll. - -You can see that the most likely square is the centre square opposite the corner -you start counting in, so check which squares you occupy or can attack before -you roll for manna. +Win by checkmate, as in regular chess, but you may use extra moves to threaten +the king. # Broken Games These ideas seemed promising, but didn't work at the table. Maybe I'll come back diff --git a/raw_rules/new_rules_contents.csv b/raw_rules/new_rules_contents.csv index 76f0ec9..e20a774 100644 --- a/raw_rules/new_rules_contents.csv +++ b/raw_rules/new_rules_contents.csv @@ -1,3 +1,3 @@ heading,description -Manna Chess,"adds random power ups to chess. (2 players, chess set, checkers set, and 2 dice)" +Adrenaline Chess,"adds power ups to chess. (2 players, chess set, and checkers set)" Cloak and Dagger Chess,"is a game where you disguise your chess pieces as checkers, then try to identify your opponent's pieces. (2 players, chess set, checkers set, pen, and tape)" diff --git a/tests/test_diagram.py b/tests/test_diagram.py index c8b5a6f..62113fa 100644 --- a/tests/test_diagram.py +++ b/tests/test_diagram.py @@ -115,6 +115,44 @@ def test_text(diagram_differ: DiagramDiffer): diagram_differ.assert_equal(svg_diagram, expected_diagram) +# noinspection DuplicatedCode +def test_corner_text(diagram_differ: DiagramDiffer): + diagram_text = dedent("""\ + . . . k q . . . + . . . . . . . . + . . . . . . . . + . . . . Q . . . + . . . P . . . . + . . . . . . . . + . . . . . . . . + . . . K . . . . + corner text: X, 4, 1 + arrow: d1, d1, gray + """) + text_args = dict(text_anchor='middle', + font_family='Raleway', + font_size=17) + expected_text = diagram_text.split('corner')[0] + expected_board = parse_board(expected_text) + expected_board_svg = chess.svg.board( + expected_board, + arrows=(chess.svg.Arrow(chess.D1, chess.D1, color='gray'),), + size=195) + Diagram.register_svg() + expected_tree = ET.fromstring(expected_board_svg) + extra = Drawing(size=(300, 240)) + extra.add(extra.text('X', (157, 345), **text_args)) + expected_tree.extend(extra.get_xml()) + expected_diagram = SvgDiagram(ET.tostring(expected_tree, + encoding='unicode')) + ET.register_namespace('', '') # Force registration again. + + diagram = Diagram(390, 195, diagram_text) + svg_diagram = diagram.build() + + diagram_differ.assert_equal(svg_diagram, expected_diagram) + + # noinspection DuplicatedCode def test_margins(diagram_differ: DiagramDiffer): diagram_text = dedent("""\