chessfidget - you call that chess?

14
ChessFidget You call that chess? 1

Upload: snoozer

Post on 15-Apr-2017

595 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: ChessFidget - You call that chess?

ChessFidgetYou call that chess?

1

Page 2: ChessFidget - You call that chess?

The itch

• Like to play chess

• Dislike losing so much

• Too much work to get good - (For me it would be a dangerous rabbit hole.)

2

Page 3: ChessFidget - You call that chess?

The scratch

• Write software to address personal shortcomings

• ChessFidget: a chess app I (currently) always beat

3

Page 4: ChessFidget - You call that chess?

Currently looks like thisIn lieu of a demo, I'll post code and (Mac) binaries

4

Page 5: ChessFidget - You call that chess?

Dev goals/guidelines• Design for dopamine, not skill

- E.g. no move history

• Computer mostly plays worse chess than I do - Currently random moves - That will get boring; see above re: dopamine

• META: Exercise in Swift and reasoning about code - NOT an exercise in chess programming or AI

5

Page 6: ChessFidget - You call that chess?

😬:Agonizing re: modeling• What are my objects? (Board, Piece, Move, ...)

• In how many places do "business rules" live? - E.g. MoveValidator and MoveGenerator - OTOH, might help with mutual unit-testing

• Sometimes the problem was a Swift difficulty - Extending Grid<T>, T is Piece? vs. T is Bool

• Sometimes the answer was a Swift feature - Type constraints?

6

Page 7: ChessFidget - You call that chess?

"Move" as struct+moveTypeenum MoveType { case resignation case plainMove case pawnTwoSquares case captureEnPassant case pawnPromotion(type: PromotionType) case castleKingSide case castleQueenSide } struct Move { let start: Square let end: Square let type: MoveType }

7

Page 8: ChessFidget - You call that chess?

Works fineawaitingHumanMoveInvalid move e1-g1: cannotCastleBecauseKingOrRookHasMovedd1-d2 (plainMove) played by White (Human)awaitingComputerMoveb8-d7 (plainMove) played by Black (Computer)awaitingHumanMovee1-c1 (castleQueenSide) played by White (Human)awaitingComputerMoved7-b6 (plainMove) played by Black (Computer)awaitingHumanMove

8

Page 9: ChessFidget - You call that chess?

"Move" as class hierarchyprotocol MoveProtocol { func updateBoard(_ board: Board) } /* The classes would be something like: Move: MoveProtocol Resignation MoveWithStart PawnTwoSquares

CastleKingSide CastleQueenSide MoveWithStartAndEnd PlainMove CaptureEnPassant PawnPromotion */

9

Page 10: ChessFidget - You call that chess?

😬:Swift overwhelm

• Building my mental model, esp. re: type system

• Finally past the squirmy phase! 😬➞😊 - New info now gets added to mental framework

• Maybe pairing would have helped?

10

Page 11: ChessFidget - You call that chess?

Thoughts about learning

• Know thy brain - Came to terms with my jumpy learning - Shlemiel the painter (stay tuned for blog post)

• Be aware when/how reach out to people

11

Page 12: ChessFidget - You call that chess?

Other thoughts• Wow do I suck at chess

• Does writing this app mean I'm a bully at heart?

• Am I weird for sensing uncanny illusion of intent? - Feels like it's capturing back "on purpose" - Feels intentional when it checks me - This despite knowing there is *zero* AI - WTF it played Fool's Mate

12

Page 13: ChessFidget - You call that chess?

Actual early test (Computer=Black)(manually recreated; wish I'd taken a screenshot)

13

Page 14: ChessFidget - You call that chess?

Next (current thinking)• Find a third-party library, add (weak) AI

• Distinguish between stalemate and checkmate

• Add keyboard input - Might help me learn algebraic notation

• Add multi-game play

• Move on to other project ideas

14