Skip to content

Instantly share code, notes, and snippets.

Mah Jong Classic Chinese Scoring, Simplified

  1. Keep track of which groups in the winning hand are concealed and which were open (revealed).
  2. Calculate base points (consider each group one at a time). See base table below. Round up to next 10.
  3. Double the base a number of times to get the score for the round. See doubles table below.
  4. Cap the score at 1000 (the limit).
  5. If the winning tile came from a discard, each player pays the winner their score, and the loser pays double.
  6. If the winning tile came from the wall, all players pay the winner double the score.
  7. Losers do not score their hands.

Base

// Imagine if we had a test framework that did this :...(
const models = require('../models')
const logger = require('../logger')
const Promise = require('bluebird')
const co = require('co')
const isGenFn = require('is-generator').fn
const colors = require('colors/safe')
function transactionStrategy(mocha) {
// These may *look* like nested conditions but they run at wildly different
// times during your program's execution.
//
// In the example below, t represents the time elapsed since starting the
// code.
//
// The user clicks the button at t = 100.
var condition1 = true;
var condition2 = true;
@puyo
puyo / hangman.html
Created October 1, 2015 06:55
Animated ASCII artwork on the JS console
<html>
<body>
<script>
var hangmanStages = [
`
@puyo
puyo / rspec-blame-filter
Last active September 28, 2015 02:10
rspec-blame-filter
#!/usr/bin/ruby
# Annotates RSpec output with contact details of the person who wrote the tests that are failing.
#
# Setup:
#
# gem install colorize
#
# Usage:
#
@puyo
puyo / check.rb
Last active May 12, 2016 00:02
RSpec feels unnecessarily verbose to me. This is an attempt at expressing the DSL I'd like to have, with a very hacky implementation that maps back onto RSpec.
gem 'rspec'
require 'rspec/core'
require 'rspec/expectations'
require 'rspec/autorun'
require 'pp'
RSpec.configure do |config|
config.color = true
config.formatter = 'doc'
config.expect_with :rspec do |c|
@puyo
puyo / alp_facebook_popularity.rb
Last active August 29, 2015 13:58
Run a Facebook based popularity competition for ALP MPs
gem 'activesupport' # {}.to_query
gem 'nokogiri'
gem 'typhoeus'
require 'active_support/core_ext/object'
require 'json'
require 'nokogiri'
require 'pp'
require 'typhoeus'
@puyo
puyo / encamel.rb
Last active August 29, 2015 13:57
#!/usr/bin/env ruby
gem 'activesupport'
require 'active_support/core_ext/string/inflections'
snake = ARGV.first
camel = snake.camelize(:lower)
system %{git grep -l #{snake} | xargs ruby -p -i -e '$_.gsub! /#{snake}/, "#{camel}"'}
@puyo
puyo / capybara_find_with_info.rb
Created January 31, 2014 04:45
More useful output from Capybara
# More useful output from Capybara.
#
# Before:
#
# Unable to find link or button "Year 5"
#
# After:
#
# Unable to find link or button "Year 5" in "Sorry, something went wrong We've
# been notified of the error and are looking into it."
$ coffee blah.coffee
Error: Cannot find module 'coffee-script'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/greg/blah.coffee:1:10)
at Object.<anonymous> (/Users/greg/blah.coffee:1:1)
at Module._compile (module.js:456:26)