This article is part of a series about functional programming concepts demonstrated on well-known kata in TypeScript. See FizzBuzz Kata: An Exploration With Functors!

Othello (a.k.a. Reversi)

In addition to being a famous tragedy by William Shakespeare, Othello is a strategy board game for two players played on an 8×8 board. It is told to require “a minute to learn, [and] a lifetime to master”. Indeed, it is not unusual to see dramatic reversals of advantage up to the end of the play. If you’re not familiar with this game and want to learn, you can give it a try online.

In this kata, we’ll try and implement the feature of telling where a player can play:

This kata expects you to write a function that, given the current board and the color about to play, computes the list of all cells where a disk of the given color can be placed. Let's take an example.

Assuming the given board:


text
  A B C D E F G H
1 . . . . . . . .
2 . . . . . . . .
3 . . . . . . . .
4 . . . W B . . .
5 . . . B W . . .
6 . . . . . . . .
7 . . . . . . . .
8 . . . . . . . .


Blacks start and can place a disk in the following cells:

text
D3, F5, E6, C4

#kata #javascript #programming-paradigms #functional-programming #iterator-pattern

Othello Kata: The Iterator Pattern in JavaScript/TypeScript Functional Programming
2.30 GEEK