LoginSignup
5
0

More than 3 years have passed since last update.

【ライフゲーム】lifegame-coreの紹介

Last updated at Posted at 2019-11-30

はじめに

この記事はGlobal Day of Coderetreat 2019 in Shizuokaに参加し、ライフゲームライブラリを作るに至るまでの話です。

Global Day of Coderetreat 2019 in Shizuoka

今年(2019年)の11/9にGlobal Day of Coderetreat 2019 in Shizuokaというイベントに参加してきました。
イベントの内容をざっと箇条書すると以下のとおりです。

  • 数十分でペアプログラミングをし、お題に沿った作品を開発する
  • 今年のお題は「ライフゲーム」

参加した感想としては、コミュニケーションを取りながらプログラミングすることが楽しいと思いました。
こういうハッカソンっぽいイベントはもっと欲しいと思いました。

このイベントをきっかけに「ライフゲームのライブラリを作ってみたいな」と思ったのでJavaScript/TypeScript向けにライフゲームのライブラリを作りました。

lifegame-core

リポジトリ:hota1024/lifegame-core
npm:lifegame-core
使用言語:TypeScript
実装の話→https://speakerdeck.com/hota1024/typescriptderaihugemuwozuo-tutemita

デモ

game.ts
import { LifeGame, ArrayWorld, BasicEnvironment, Cell, ConsoleWorldRenderer, CellState } from 'lifegame-core'

const game = new LifeGame(new ArrayWorld(20, 20, Cell), new BasicEnvironment()) // Create 20 x 20 world.
const renderer = new ConsoleWorldRenderer() // Create console world renderer.

// Random generate.
game.setEach(() => {
  return Math.random() > 0.5 ? CellState.Dead : CellState.Living
})

// Tick function.
const tick = () => {
  console.clear() // Clear console.
  renderer.draw(game.world) // Draw.
  game.forward() // Forward.

  setTimeout(tick, 500)
}

// Start
tick()

最後に

こういうイベントに行くと何かを作りたくなるのでどんどんイベントに参加していきたいと思います。

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0