GithubHelp home page GithubHelp logo

othello-scala's Introduction

othello

Type-safe Othello written in Scala

Play

sbt "runMain io.github.nwtgck.othello.Main"

(In the future, this may be changed.)

AI

This game has three types of AI for now.

  • RandomPlayer - moves randomly
  • MonteCarloPlayer - moves by Monte Carlo method
  • UguisuEvaluationTablePlayer - moves by a evalutation table found in http://uguisu.skr.jp/othello/5-1.html
  • MinimaxPlayer - moves by minimax method with alpha-beta pruning

Type-safety

For example, Disk and Cell are not the same. Disk is a subset of Cell, mathematically, Disk โŠ‚ Cell. Because of this definition, Player has Disk, not Cell since Player should not have Empty, which is a state of a cell.

/**
  * Cell
  */
sealed trait Cell

/**
  * Disk (Disk is a subset of Cell)
  */
sealed trait Disk extends Cell{
...
}
case object Black extends Disk
case object White extends Disk
case object Empty extends Cell

If union types are available like TypeScript, the type definition will be more clear like the following. This project will be written in Dotty when Dotty get more stable.

// NOTE: TypeScript
type Cell = "Black" | "White" | "Empty"
type Disk = "Black" | "White"

For another example, the parameters of Game class ensure to have valid players like the following.

class Game(player1: Player[Black.type], player2: Player[White.type]) {
 ...
}

(The player1's disk is always Black and the player2's disk is always white.)

Definition of Player abstract class is like the following.

abstract class Player[+D <: Disk] (val disk: D) {
  ...
}

Game Tree

Game tree is represented as lazy tree. So you can get entire game tree by the following.

// The entire game tree of Othello!
GameTree.create(GamePosition(
  board = Board.initial,
  disk  = Black,
  previousMoveOpt = None
))

Here is a visualization of the game tree where depth limit = 3.

Othello Game Tree Visualization

othello-scala's People

Contributors

nwtgck avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.