Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Learn more about F# at http://fsharp.net. See the 'F# Tutorial' project
// for more guidance on F# programming.
#light
open Microsoft.FSharp.Reflection
let Fail message = failwith message
let IsTrue(success) = if not success then failwith "Expected true"
let AreEqual(expected, actual) =
if not (expected = actual) then
sprintf "Expected '%A' Actual '%A'" expected actual |> failwith
let Throws<'T when 'T :> exn> (f) =
let fail () = failwith "Expected %s" typeof<'T>.Name
try f (); fail () with :? 'T as e -> e | _ -> fail()
// -------------------------------------------------------------------------------
type Resource = Blue | White | Orange | LightBrown | Green
type UrbanizationToken = A | B | C | D | E | F | G | H | I | J | K | L
type UrbanizationCard = UrbanizationToken
type BuildingColor = Blue | Red | Yellow
type BuildingNum = int
type BuildingTile = {color:BuildingColor; number:BuildingNum}
type BuildingCard = BuildingTile
type Card =
| UrbanizationCard of UrbanizationCard
| BuildingCard of BuildingCard
type GreenSpaceTile = unit
type Tile =
| BuildingTile of BuildingTile
| GreenSpaceTile of GreenSpaceTile
type CharacterCard = unit
// --
// http://www.devx.com/dotnet/Article/40537/0/page/3#sthash.xM1pn761.dpuf
let randomNumberGenerator =
new System.Random()
let shuffle cards =
let upperBound = (List.length cards) * 100
let weightedCards =
List.map
(fun card -> card, randomNumberGenerator.Next(0, upperBound))
cards
let sortedWeightedCards =
List.sortWith
(fun (_, leftWeight) (_, rightWeight) -> leftWeight-rightWeight)
weightedCards
List.map
(fun (card, _) -> card)
sortedWeightedCards
let initialCity =
[for num in 1 .. 3 do
for color in [ Blue; Red; Yellow ] -> BuildingCard {color=color; number=num} ]
printf "%A" initialCity
let shuffled = shuffle initialCity
printf "%A" shuffled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.