Predator: A Framework for developing programmatic players for Complex Board Games( in Erlang and PureScript)

Summary: An Experience Report on How I'm using Erlang and PureScript to create programmatic opponents aka 'bots' for complex boardgames I love to play but I can't find people to play with!

The number of boardgames that you can whip out at a gathering and expect people to want play is very small.. Monopoly, Snakes and Ladders, perhaps Settlers of Catan. And that's about it.
Getting people to play these games is relatively easy.

However the world of boardgames is *much* wider. There are literally tens of thousands of boardgames that simulate everything from very abstract geometry puzzles to ones thatcomplex economies and political situations. Some of the latter are used in very unexpected ways, e.g to train spies and military officers.

Here is an example

A Distant Plain (by GMT Games) is a boardgame for 4 players that put them in the roles of the US military forces, the Afghan government, the Taliban, and Warlords cum drug dealers, all competing for power in Afghanistan.

DistantPlain1

 

Here is another
The War of the Ring, a game for 2 players.

"In War of the Ring, one player takes control of the Free Peoples (FP), the other player controls Shadow Armies (SA). Initially, the Free People Nations are reluctant to take arms against Sauron, so they must be attacked by Sauron or persuaded by Gandalf or other Companions, before they start to fight properly ...."

WarOfRings1

And one more

"A game of Eclipse places you in control of a vast interstellar civilization, competing for success with its rivals. You will explore new star systems, research technologies, and build spaceships with which to wage war. There are many potential paths to victory, so you need to plan your strategy according to the strengths and weaknesses of your species, while paying attention to the other civilizations' endeavors."

 

What these games have in common
1. They are wonderful wonderful games, immersing you into their respective worlds.
2. They have (relative to Snakes and Ladders or Monopoly) complex rulesets.
3. They are rarely played in India.
4. Even when people own them, opponents are almost impossible to find and schedule.

Which means that if you own these games and live in India, getting to actually play these games is close to impossible. Which is a problem.

Being a programmer, I solve this problem by writing programmatic opponents (aka 'bots') to take the place of other players. This involves all kinds of interesting sub problems - game representation, logic processing for rules, building AI 'smarts' for your opponents, gui and event handling etc.

Since I am doing this in my non existent spare time, I use time and effort saving languages, aka functional languages, in my case Erlang (originally Haskell) for the backend and PureScript for the front end.

This talk is about the many challenges I faced in building automated game players (and extracting common frameworks/libraries) from them. Since this is an experience report, it is basically a list  of lessons learned, victories *and defeats*, what worked *and what didn't work*.

If you can't use FP at work, but are considering doing so on a personal project, or want to learn how to get going on a non-toy FP learning effort, you could benefit from my mistakes and successes.

 
5 favorite thumb_down thumb_up 0 comments visibility_off  Remove from Watchlist visibility  Add to Watchlist
 

Outline/structure of the Session

-This is an experience report and so is structured as a series of programming/design challenges, solutions tried, final adopted strategy etc for a series of subproblems.

The following is tentative, but likely close to what I'll end up with.

  • General Overview
  • Some information on a specific boardgame (likely "A Distant Plain"  - the first in the list of  3  in the talk description, which I'll use as a running example.
  • Then a series of code/demo bits on the various subsystems
  • How to test if bots are under or over powered. A brief digression into applied statistics
  • State of play  - what works
  • What remains to be done
  • Since this is my first non-trivial project in Erlang (my usual toolset is Haskell + C + Lua), I'll talk about what I learned with respect to using (and abusing!) Erlang
  • Conclusion and QA

Learning Outcome

This is an experience report of a project. What you'll learn is largely up to you. 

That said, programming *boardgames* (vs first person shooters or platform games) have some unique challenges.  From my progress (and failures!) you  can learn which subproblems FP is a good fit for, and where it is harder than it needs to be.

If you are interested in any of the technologies used (here Erlang, Purescript, some Haskell) you might want to attend.

Target Audience

Anyone

Prerequisite

Nothing.

If you play boardgames, or have an interest in them,and/or you use functional languages, either professionally, or for your personal projects, you might appreciate the nuances more, but no real pre requisites otherwise.

 

schedule Submitted 1 month ago

Comments Subscribe to Comments

comment Comment on this Proposal

  • Liked Manuel Chakravarty
    keyboard_arrow_down

    Haskell SpriteKit - a Purely Functional API for a Stateful Animation System and Physics Engine

    Manuel Chakravarty
    Manuel Chakravarty
    Lambda Scientist
    UNSW Sydney
    schedule 1 month ago
    Sold Out!
    45 mins
    Demonstration
    Intermediate

    Graphics, animation, and games programming in Haskell faces a dilemma. We can either use existing frameworks with their highly imperative APIs (such as OpenGL, Cocos2D, or SpriteKit) or we waste a lot of energy trying to re-engineer those rather complex systems from scratch. Or, maybe, we can escape the dilemma. Instead of a Haskell program directly manipulating the mutable object-graph of existing high-level frameworks, we provide an API for purely functional transformations of a Haskell data structure, together with an adaptation layer that transcribes those transformations into edits of the mutable object-graph.

    I this talk, I will explain how I used this approach to architect a Haskell binding to the animation system and physics engine of Apple’s SpriteKit framework. I will discuss both how the binding is structured and how it achieves the translation of Haskell side changes to SpriteKit and vice versa, such that it is sufficiently efficient. Moreover, I will demonstrate by example how to use the Haskell library to implement a simple game.

  • Liked Manuel Chakravarty
    keyboard_arrow_down

    Functional Programming in Swift

    Manuel Chakravarty
    Manuel Chakravarty
    Lambda Scientist
    UNSW Sydney
    schedule 1 month ago
    Sold Out!
    480 mins
    Workshop
    Beginner

    Swift’s strong functional programming support generates a lot of interest in adapting functional programming techniques to improve designing, developing, and maintaining Cocoa applications. This workshop will help you unlock this potential.

    We will explore the foundations of functional programming and how functional programming helps to improve software development. We will start by discussing the main goals of functional programming, followed by surveying Swift’s language features that support functional programming. Then, we will look at how to put functional programming principles into practice using Swift. We will focus on immutable data structures, value types, and functional reactive programming.

    = Value types 

    One of the biggest changes in the transition from Objective-C to Swift is the new type system. This change is at the heart of Swift’s language design, from optionals over value types to constrained generics, and to truly understand the language, a thorough understanding of its type system is indispensable. We will survey these type system features with special attention to value types. We will discuss how structs and enums in Swift can be used to help avoid bugs by design and how immutable data structures help to avoid unwelcome side effects.

    = Functional reactive programming

    Functional reactive programming (FRP) promises to replace unstructured side effects by structured change propagation in response to user input, network events, sensor activity, and similar. Typically explained by way of sophisticated, but often also complex functional reactive programming frameworks, such as ReactiveCocoa and RxSwift, it can be difficult to see the simple principles underlying functional reactive programming. In fact, these principles are sufficiently simple that we can explain them by building a functional reactive programming library from scratch.

    We will discuss how we can construct our own lightweight functional reactive programming library out of simple components using Swift’s support for protocol-oriented programming. Moreover, we will discuss how to use this library to design and implement the change propagation between the model and view components of a Cocoa app. 

    All of this is illustrated with hands-on coding exercises based on simple iPhone application that incorporates the discussed techniques.

  • Liked Maria Livia Chiorean
    keyboard_arrow_down

    The path to generic endpoints using Shapeless

    20 mins
    Talk
    Beginner

    Programming in Scala is sometimes very time consuming. Finding the most efficient way to solve a problem can end up in days of frustration. This talk is a story of trail and error with a twist at the end. It's a story of API endpoints, generic programming, Shapeless and what happens when they all come together. Everything with examples and plenty of code.

  • Liked Paweł Szulc
    keyboard_arrow_down

    Going bananas with recursion schemes for fixed point data types

    Paweł Szulc
    Paweł Szulc
    Scala Developer
    Slam Data
    schedule 3 months ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    In 1991 Erik Meijer, Maarten Fokkinga, and Ross Paterson published "Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire." This paper is a classic one, widely recognizable in the FP community. Constructs described - known as recursion schemas - have real world applications. Strictly speaking, explicit recursion is the ‘goto’ of pure functional programming. Recursion schemas provide same level of sanity as loops did for structural programming back in the day.

    Over the years a lot of the progress have been made. Papers like "Recursion schemes from comonads" by Tarmo Uustalu, Varmo Vene & Alberto Pardo or "Unifying Structured Recursion Schemes" by Ralf Hinze, Nicolas Wu & Jeremy Gibbons - pushed the concept forward.

    This talk is about generalization of a very specific recursion schema (called catamorphism) over fixed point data type. After providing introduction the concept of catamorphism, we will jump straight to fix point data types trying to solve some real-world problems. Code examples are in Scala. Code examples use Matryoshka - which is an open sourced project design to generalize folds, unfolds, and traversals for fixed point data structures in Scala.

  • Liked Manoj Govindan
    keyboard_arrow_down

    Learning Computer Architecture With Erlang

    Manoj Govindan
    Manoj Govindan
    Developer
    Perfios
    schedule 6 days ago
    Sold Out!
    45 mins
    Experience Report
    Intermediate

    Computer Architecture begins with electronics. As computers are built layer upon layer starting with primitive gates baked into silicon, followed by chips and logic gates, hardware platform including ALU, RAM, cache etc., and so on, so is the study of computer architecture a study of each of these layers of abstraction.

    Students of computer architecture usually rely on simulators, often written in Java or similar imperative/object oriented languages, to aid their learning. Here are some examples of such a program: 

    Simulating XOR gate

    As an Erlang/functional programming enthusiast studying computer architecture I decided to write my own equivalent tools in Erlang and TypeScript as I went about my learning. I am studying computer architecture and simultaneously writing the required simulators and other tooling in Erlang and TypeScript.

    Building such emulators and tools in Erlang and Typescript results in distinctly different architectures. I'll be demoing the simulator I built and talking about lessons learned doing this. 

  • Liked Aloïs Cochard
    keyboard_arrow_down

    The Tale of Troy

    Aloïs Cochard
    Aloïs Cochard
    CTO
    BestMile
    schedule 1 month ago
    Sold Out!
    45 mins
    Talk
    Beginner

    In recent years, the impact of functional programming on mainstream languages has grown significantly.

    After conquering server applications and distributed systems,
    the paradigm is now conquering the fields of web development and data analytics.

    So what remains? The land of system programming.

    When Mozilla did release the language Rust in 2012,
    it did immediately striked interest from functional programming enthusiasts due to it's strong emphasis on safety.

    Even though it currently lacks some advanced features like higher kinded types,
    it is built with functional programming principles as it's core.

    Like a Trojan horse (or the parasite mushroom after the language is named),
    Rust looks like the next C on the outside... while it might actually be closer to Haskell on the inside!

    Let's take a tour and discover an other side of system programming by learning together how to do functional programming in Rust.

  • Liked Ryan Lemmer
    keyboard_arrow_down

    From Haskell 98 to Modern Haskell - Making sense of the Haskell type system

    45 mins
    Talk
    Intermediate

    There are several great books and courses that serve as an introduction to functional programming in Haskell. Typically, these introductions focus on the original core of Haskell ("Haskell 98").

    However, going from there into real world Haskell systems can be a bewildering experience. This is because Haskell has evolved significantly since Haskell 98. In this talk we will investigate the key advances in the type-system that make up "modern Haskell".

    • type-system extensions: Rank-n types, GADTs, functional dependencies, ...
    • kind-system extensions: type functions, kind polymorphism, type promotion, ...

    By taking a historical perspective we will look at why new language extensions were introduced, and the context in which they first appeared. This approach gives us a layered view of seemingly disparate language features.

    We will see that the evolution of the type system has been a steady march from "programming with types" to type-level programming, and ultimately dependently-typed programming in Haskell.

    (This talk will draw from the book "Haskell Design Patterns")

  • Liked Nikhil Tibrewal
    keyboard_arrow_down

    Scio – Scala DSL for Apache Beam

    45 mins
    Talk
    Intermediate

    Apache Beam (based on Google’s Dataflow Model) provides a simple, unified programming model for both batch and streaming data processing. If only it wasn’t so unfamiliar and verbose for our Scala engineers. Learn how Scio leverages Scala’s type system, macros and functional paradigm to provide more engineer-friendly and type safe API.

  • Naresh Jain
    Naresh Jain
    Founder
    ConfEngine.com
    schedule 3 months ago
    Sold Out!
    45 mins
    Demonstration
    Intermediate

    Array-oriented Programming (AoP) dates back to 1960s.The fundamental idea behind AoP is that operations apply at once to an entire set of values. This allows the programmer to think and operate on whole aggregates of data, without having to resort to explicit loops of individual scalar operations. At ConfEngine.com, a platform for organising and managing technical conferences/events, we've been heavily influenced by the APL style of AoP. In our context, this means each function focuses on applying one transformation to an immutable array (ordered-map) and then spitting out a new array, which can be piped to another function thus achieving functional composition. This has allowed us to build a very modular, decoupled design, which is extremely simple to reason about. 

    If you think of typical web-apps, they are generally CRUD applications. Data comes in, you apply a set of transformation and you pass it to someone else via an API or you save/query a data store. And on the way out, you get data from somewhere (data-store, API, etc.), apply a set of transformations and render the transformed data as HTML or JSON. Now we can visualise most web-apps using standard Pipe-and-Filter Architecture. With this, applying some of the functional programming concepts becomes more intuitive.

    At ConfEngine.com, we use the standard LAMP stack. We've used PHP's philosophy of shared-nothing-architecture to address concurrency and scalability concerns. PHP itself has all the basic ingredients required for Functional Programming - first-class, higher-order functions, lambda, closures, partial functions, recursion and so on. We use array (ordered-map) to hold the data. PHP provides 79 array functions that allows you to do pretty much everything you need to in terms of transforming arrays including map, reduce, filter, merge and so on. One needs to be careful, but most of these are pure, higher-order functions. 

    If you are interested to learn more about AoP, I'll give a walk through of our design. Also I'll take a couple of problems to explain how to think in terms of AoP and how its really helps with functional programming.

  • Liked Arthur Kushka
    keyboard_arrow_down

    Recursion schemes and fixed point data types

    Arthur Kushka
    Arthur Kushka
    Software developer
    AutoScout24 GmbH
    schedule 3 months ago
    Sold Out!
    45 mins
    Talk
    Advanced

    Its always challenge to build a good abstraction during work on library. Library codebase must be flexible and modular when user code must be clean and easy understandable. One of variants to build API between library and customer its Free evaluation approach. In that case you as developer is free to interpret customer actions as you want and customer is free to define actions as he want. In my talk I will show how to build API based on recursive abstract data types, describe why its cool and demonstrate some tricks on type system to make customer experience with library better.

     
  • Debasish Ghosh
    Debasish Ghosh
    Consultant
    IRadix Inc
    schedule 2 weeks ago
    Sold Out!
    45 mins
    Experience Report
    Intermediate

    Using a programming language that supports first class functional programming doesn’t necessarily imply that the code you write is functional. Functional programming has the nice properties of being compositional - you design smaller abstractions and then reuse them to build larger ones. You use the power of algebraic properties that these abstractions offer to build larger elements of your model out of smaller ones.

     However often we find that many code bases designed in a functional programming language are inherently imperative, especially when you are using a multi-paradigm language like Scala or Java. There’s nothing wrong with imperative code, but it lacks the niceties of expression based composition that makes reasoning about your code so much easier. Also assignments used in imperative code are inherent side-effects that are best avoided (or at least minimized) in an expression oriented language.

     In this session I will discuss some of my experiences of mining imperative code and refactoring them into functional patterns. You will be surprised to see how much functional goodness can be derived through functional thinking. Algebraic structures like Monoids, Monads and Kleislis are just buried within the reams of imperative statements crying to come out. In an exercise of half an hour we will liberate them and see how the code quality improves from the point of view of modularity, compositionality and simplicity.

  • Calascibetta Romain
    Calascibetta Romain
    Independent
    OCaml Labs
    schedule 1 month ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    Git is one of the most popular tool for a developper and a part of the power of Git is come from some functional concepts. So, it's obvious to implement the Git format with OCaml!

    This talk will present the functionnal concepts of Git (like the immutable tree) and show a practical implementation with OCaml step by step. Then, we will explain how can scale an OCaml code to compute a huge Git repository and understand by this way the power of OCaml (and the mix between the functionnal and the imperative way).

    At the end, we will show an example of the usability of Git with OCaml with a concrete application.

  • Liked Roger Hui
    keyboard_arrow_down

    Proofs, Derivations, Tests

    Roger Hui
    Roger Hui
    programmer
    Dyalog Ltd.
    schedule 1 month ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    John Hughes and Mary Sheeran in Why Functional Programming Matters [0] list “algebra as a litmus test” as one of the four salient features of functional programming, and Ken Iverson in Notation as a Tool of Thought [1] lists “amenability to formal proof” as one of the five important characteristics of notation. Using the language APL, we prove the correctness of some programs, derive simplifications, and illustrate design validation and program test techniques for functional programs.

    [0] Hughes, John, and Mary Sheeran, Why Functional Programming Matters, Code Mesh, London, 2015-11-02 to -04.

    [1] Iverson, Kenneth E., Notation as a Tool of Thought, Communications of the ACM, volume 23, number 8, 1980-08.

  • Liked Ryan Lemmer
    keyboard_arrow_down

    Haskell Design Patterns

    480 mins
    Workshop
    Intermediate

    In this workshop we explore several areas of advances that make up Modern Haskell.

    (This is an experiential workshop, we will code together, and explore ideas together from first principles. You will need GHC 7.10 and up.)

    Patterns for IO

    Experience the 3 styles of IO programming in Haskell, in the order in which they evolved:

    * imperative style (the status quo)
    * Lazy IO and its limitations
    * Iteratee IO, the solution to Lazy IO

    As we compare the different styles, we will pay attention to

    * what controls evaluation
    * space and resource management
    * the relationship between producer and consumer

    From Foldable, Traversable to Lenses

    We follow the evolution of fold and map on lists, to their generalisation over arbitrary types with the Foldable and Traversable type-classes. 

    The Lens library raises Foldable and Traversable to an even higher level of abstraction. We will see how the Lens library gives a unified vocabulary for traversal of arbitrary data structures.

    Functor, Applicative, Arrow, Monad

    These data types fall on a spectrum of power and generality (Functor being the most general, and Monad the most powerful). By experiencing how these types differ in the way they compose, we can gain a clearer understanding of where and how each type may be used.

    Datatype Generic Programming (bonus material)

    This style of Haskell programming is based on a simple technique: instead of defining functions for ad-hoc types, we deconstruct our types into a more fundamental type representation, and then write generic functions against the lower-level type. These generic functions are impervious to changes in the original, higher-level data types.

    We will experience datatype generic programming from first principles, and along the way uncover the key ingredient in the magic sauce called GHC.Generics.

  • Liked Eric Torreborre
    keyboard_arrow_down

    The Eff monad, one monad to rule them all!

    Eric Torreborre
    Eric Torreborre
    Senior Software Developer
    Zalando
    schedule 5 months ago
    Sold Out!
    45 mins
    Talk
    Advanced

    Monad transformers are a neat way to compose effectful computations: pass some configuration, read/write from disk, track errors... However they can be a bit cumbersome to deal with, especially if you want to use different stacks sharing some common effects: for example a stack to interact with AWS and another one for Hadoop computations.

    This talk will shortly introduce monad transformers in Scala and their drawbacks then present the Eff monad.

    The Eff monad has some really interesting properties:

    • effects can be developed completely independently from each other
    • effects can be interpreted in different ways and the interpreters can be composed together
    • it is based on an efficient "Free monad" (avoiding the issue of quadratic flatMaps)
    • with the Eff monad you will never have to re-implement the Monad operations (point / flatMap) again!
  • Liked Abhiroop Sarkar
    keyboard_arrow_down

    Wormholes and teleporting with Transient.

    45 mins
    Talk
    Intermediate

    The transient library in Haskell/Eta composes arbitrary pieces of software in concurrent, parallel and sequential settings using standard Haskell/Eta combinators like applicative, alternative, bind etc. It provides algebraic and monadically composable primitives for concurrency, parallelism, event handling, transactions and multithreading

    It liberates the programmers from dealing with state machines, objects frameworks, routes, configurations and callbacks. Transient expresses business functionalities as compact category theoretical expressions which compose. These compositions are verified during compilation, although the code might be executing in different machines.

    It presents a fresh new approach to programming concurrent and distributed systems.

     

  • Liked Eric Torreborre
    keyboard_arrow_down

    Streams, effects and beautiful folds, a winning trilogy

    Eric Torreborre
    Eric Torreborre
    Senior Software Developer
    Zalando
    schedule 5 months ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    Most applications are just reading data, transforming it and writing it somewhere else. And there are great libraries in the Scala eco-system to support these use cases: Akka-Stream, fs2, Monix,... But if you look under the hood and try to understand how those libraries work you might be a bit scared by their complexity!

    In this talk you will learn how to build a very minimal "streaming library" where all the difficult concerns are left to other libraries: eff for asynchronous computations and resources management, origami for extracting useful data out of the stream. Then you will decide how to spend your complexity budget and when you should pay for more powerful abstractions.

  • Liked Oskar Wickström
    keyboard_arrow_down

    The Power of Functional Programming and Static Type Systems in Server-Side Web Applications

    Oskar Wickström
    Oskar Wickström
    Programmer
    Empear
    schedule 7 months ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    Single-page web applications have been spreading like wildfire, with an endless amount of frameworks and libraries, and functional programming together with static types fueling the fire with great ideas like pure functions, monads, and strong type checking. But what happened to Progressive Enhancement? Some parts of our applications might require Javascript to function, but the majority could be built with ordinary links and forms.

    In this talk we will explore how we can build web applications using established web technology, and the power of functional programming on the server-side, leveraging what is already in our browsers.

  • Liked Shripad Agashe
    keyboard_arrow_down

    More is different: Mistaking trees for Forest

    Shripad Agashe
    Shripad Agashe
    Sr Architect
    Vuclip India
    schedule 1 month ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    Generally scientific approach is kept limited to only reductionist approach i.e. trying to understand the system by understanding its parts. Thats how we have been taught to think. However this construct fails in non trivial systems. Often the property of the system can not be reduced to any property of its constituent parts. To take an example “pressure” is not a property individual atoms/molecules but that of a gas. In any complex system it is important to identify relationship between the property of the system and property of its parts. This relationship is known as emergence in complex systems.

    In this talk I would cover variety of techniques I’ve used to identify emergent properties. It helped me unravel knotty designs and truly understand “deep insight” aspect of domain driven design. I feel this topic is important in the context of functional programming as functions are touted “pure” abstractions: missing the point of interaction.