Project 2: Ataxx
Introduction, Board.java and Move.java
DISCLAIMER: This video/slide deck is in no way a replacement for reading the project spec.
CS 61B // Spring 2022
Copyright By PowCoder代写 加微信 powcoder
● Introduction
○ Rules of the game
○ Your Task
○ Demo (with staff-ataxx)
○ Food for thought
● Project 2
○ Overview of the skeleton code
○ Implementation Quirks
○ Move.java and Board.java
○ Tips, Tricks
CS 61B // Spring 2022
Starting a game of Ataxx
● 2 player game played on a 7×7 board, rows denoted 1-7, columns a-g (kind of like chess, if you are familiar)
● Red/blue pieces that fill each cell, or empty
● Initial Board:
○ Red in top left/bottom right (a7/g1)
○ Blue in bottom left/top right (a1/g7) ○ Red moves first
7 6 5 4 3 2 1
CS 61B // Spring 2022
Making a Move
○ Place a new piece of your color next to an existing
○ Horizontally, vertically, diagonally adjacent
○ Move a piece of your own color to a square that is
no more than two rows and two columns away
● When making a move, all opposing pieces next to the moved piece are replaced by pieces of your color
7 6 5 4 3 2 1
7 6 5 4 3 2 1
CS 61B // Spring 2022
Making a Move Pt. 2
● When making a move, all opposing pieces next to the moved piece are replaced by pieces of your color
44 33 22 11
abcdefg abcdefg
CS 61B // Spring 2022
Making a Move Pt. 3
● Sometimes you can’t… ○ Red must pass
○ A player can only pass if they cannot move
CS 61B // Spring 2022
Winning Ataxx
● When the game ends, the player with the most pieces on the board wins
7 ○ Results in a tie/draw if there are the same number of red 6
and blue pieces on the board ● Conditions that end the game:
○ Neither player can make a move (the board is full)
○ A player has no pieces of their color on the board 2
○ There are 25 consecutive jumps without any extends
CS 61B // Spring 2022
A bit more spice…
○ Placed before either player makes a move (like setting
7 the size of the board in Project 0) 6
○ Placed symmetrically around the center of the board
○ Pieces cannot be placed on these blocks
CS 61B // Spring 2022
● Implement the logic of Ataxx
○ What kind of move a move is, setting up the initial board, determining if a move is allowed, making a
move and updating the board accordingly, setting blocks etc…
○ This is similar to Project 0: Blocks, but with some quirks
● Implement an “AI” player that you can play the game against
○ The AI needs to be able to force a win if possible within four moves of a given position
○ The AI also must not use more than 10 seconds to make any given move
○ Worry not, we will go over techniques for doing this in lecture
CS 61B // Spring 2022
Demo (staff-ataxx)
CS 61B // Spring 2022
Food For Thought
● As always, start early! The checkpoint is a good sanity check, but give yourself plenty of time for debugging at the end.
● This project has a big codebase, but you know Java, so don’t be afraid of it! If something is broken, go digging. There is no such thing as an unsolvable bug, and you have the skills to solve most issues.
○ Use the IntelliJ debugger! You will not have this luxury in other CS classes.
○ TAs will expect significant debugging effort if you submit a gitbug.
○ Taking a break can help a ton with debugging!
● Read the spec and skeleton code comments. This is the most useful source of information (it’s the instructions). If you are stuck, there’s probably something useful in the spec or skeleton code comments that you may have glossed over.
● Enjoy! You’ll learn a new game and make an automated player (that can probably kick your butt).
CS 61B // Spring 2022
Overview of the Skeleton Code
CS 61B // Spring 2022
Implementation Quirks
● Behind the scenes, we use an 11×11 Board, rather than a 7×7 board. Anything outside of the actual 7×7 board
should be initialized to “BLOCKED”.
○ Removes the need
for edge cases when
near the edge of the board!
● Instead of a 2D array, we use a 1D array for our Board!
○ For efficiency when copying
the Board (we want our AI to be fast)
○ Consider each successive row as after each other, see diagram for indices in the 1D array
‘7’ +2 ‘7’ + 1 ‘7’
‘5’ ‘4’ ‘3’
‘1’ – 1 ‘1’ – 2
‘a’ ‘b’ ‘c’
‘d’ ‘e’ ‘f’ ‘g’
CS 61B // Spring 2022
(More) Implementation Quirks, Tips, Tricks
● We abstract much of this away!!!
○ You can get/set based on row/ col
label, which are type char
● Remember, chars are stored as bits, so
they can be manipulated in weird ways:
‘7’ +2 ‘7’ + 1 ‘7’
(char) (‘a’ – 1); // result is the char before ‘a’, ‘`’ (char) (‘a’ + 2); // result is the char 2 after ‘a’, ‘c’ ‘4’
(int) ‘1’; // result is 49, the int corresponding to the
// bits that make up ‘1’
‘3’ ‘g’ – ‘a’; // result is 6, the difference between the bits‘2’
// that make up ‘g’ and ‘a’
● You can try playing around in a java interpreter here (type `jshell` into the terminal on the right)
‘1’ – 1 ‘1’ – 2
‘a’ ‘b’ ‘c’
‘d’ ‘e’ ‘f’ ‘g’
CS 61B // Spring 2022
Move.java, Board.java
CS 61B // Spring 2022
Tips, Tricks
● You might consider creating some static final constants (e.g. an array of all of the column chars and row chars) if you find it helpful or reuse a constant often!
● Use the helper methods/ methods already defined in the skeleton (abstraction is your friend)!
● If you are writing tons of if cases checking edge conditions and doing a lot of error checking, stop! The implementation quirks should resolve the need for too many edge cases, and the given skeleton should handle input errors.
● Consider using Project 0 for inspiration for undo! The skeleton for undo is set up with efficiency in mind– think about exactly what information you need in order to undo a move.
CS 61B // Spring 2022
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com