Tic Tac Toe in SwiftUI, Done Properly: Value-Type State, Win Detection and Minimax AI

https://hackernoon.imgix.net/images/O4uf0oJl74dQN4mv96aWCFoPnK02-c002bmb.jpeg

The smallest game worth architecting: an immutable board, testable rules, a view that just renders state, and the classic AI you can bolt on in 40 lines

Tic tac toe is the "hello world" of game development, which is exactly why it's worth doing properly. It's small enough to hold in your head, but it still has every piece a real game needs: state, rules, turns, an end condition, a UI that reflects state, and, if you want it, an opponent that thinks.

One of my earliest App Store apps is Tic Tac Toe: Time Pass, published in April 2020. Its listing is as short as the game: "Put away your pencil and paper", with one-player and two-player modes, so you can play against another person or against yourself.

This article uses tic tac toe to show an architecture I'd use for any turn-based game: a value-type modelthat...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more