I wrote:For this problem, I'll use main() as my drawing board.
Stephan van Hulst wrote:I could imagine that for a first version, the Game just keeps going until the Board is full. There are no computer players, and there are no checks to see if there are three marks in a row. I would write the relevant test cases, and then implement those types.
Prasanna Raman wrote:I thought about the design and have come up with the following classes:
Game
Attributes - Board and players.
Behaviour - update the board, check if game has ended and/or find a winner and regulate players' turns.Board
Attributes - rows and columns. So I will need a data structure to store the board in.
Behaviour - get updated by the game to reflect its latest statePlayer
Attributes - symbol
Behaviour - playSymbols - an enum class storing "X" and "O"
Please take a look and let me know the flaws in this design.
Stephan van Hulst wrote:it now also has to provide methods such as one to see if a square is occupied by a certain mark.
Stephan van Hulst wrote:How is the outside world to know what spots it can mark without causing an error?
Junilu Lacar wrote:You might also allow it to be queried with List<Integer> legalMoves().
Campbell Ritchie wrote:Would you want 1‑based numbers?
Using the int literals 1 and 9 restricts you to a 3×3 board.
Junilu Lacal wrote:
Junilu Lacar wrote:
Liutauras Vilda wrote:
For me personally:
Adds a bit more clarity what's potentially going on behind the hoods. Doesn't that mean code is better readable?
What about availableMoves()?
What are your thoughts?
Liutauras Vilda wrote:And no, TDD is not easy, which seems to be conceptually a trivial thing, practically is very difficult.
It is very weird feeling, I feel that I very well envision and understand the value of practicing TDD, but yet, couldn't make it in practice.
Liutauras Vilda wrote:A bit philosophical...
...
Over here, nothing moves nowhere. Players i.e. just marking the board.
But perhaps that word "moves" is a bit ambiguous in general when used in the sentence.
Campbell Ritchie wrote:Would you want 1‑based numbers?
Using the int literals 1 and 9 restricts you to a 3×3 board.
Junilu Lacar wrote:ZOMBIES says to start with simple scenarios to get simple solutions. If we're only talking about TicTacToe, I'd rather stick with its constraints instead of trying to think about how to accommodate other kinds of constraints.
Sandi Metz (@sandimetz) wrote:Don't write code that guesses the future, arrange code so you can adapt to the future when it arrives."
Junilu Lacar wrote:Here's one question I would ask:
Between hasLegalMoves() and boardAllMarked which one is more aligned with intent rather than implementation?
Junilu Lacar wrote:Another strategy that allows for flexibility is ignoring edge infrastructure concerns for as long as possible. When you do need things like printing out your object or saving it somewhere, I try to keep it as simple and generic as possible. For example, instead of putting a bunch of System.out.println() statements inside the class, like in a show() method for example, I just make the class emit a String representation of itself and let the client worry about what to do with that representation.
I find this easier than adding a bunch of getter methods to be used to query the object's state. To give even more options, I might think of emitting the object's representation as a JSON string.
Consider Paul's rocket mass heater. |