Code Monkey home page Code Monkey logo

chomp's Introduction

Chomp

Bart Massey, 2013-06-20

  1. Build a move struct with a row and column index.

  2. Your board will be a R x C array of "boolean". I will assume that this array is zero-based in this pseudocode. Initially, let R = 3, C = 4.

  3. Write a function/method to initialize a board to all true.

  4. Write a function to print a board (in ASCII, because graphics code takes forever). I used o and . as the board characters.

  5. Write a function to make a move gotten from a human. Use whatever syntax is easy and makes you comfortable. Your function should return a valid Move struct. Don't overdo the error checking and beauty at this stage. My function took seven lines.

  6. Write a function to make a move r, c on a board, by changing all squares that are at or below both r and c to false.

  7. OK, here comes the interesting part...

     negamax(b, d):
       rx <- 0
       cx <- 0
       for r in 0..R-1
         for c in 0..C-1
           if b[r][c] ^ (r > 0 v c > 0)
             rx <- r
             cx <- c
             b' <- copy b
             makeMove(b', r, c)
             if negamax(b', d + 1)
               continue
             if d = 0:
               makeMove(b, r, c)
               print the move r, c
               print that the program is winning
             return true
       if d = 0 --- no winning moves, so just pick a loser
         makeMove(b, rx, cx)
         print the move rx, cx
         if rx = 0 ^ cx = 0
           print that the program has lost
         else
           print that the program is losing
       return false
    
  8. Now you just need to write a main program that alternately calls negamax() and your human move() function until someone loses.

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.