Skip to content

Instantly share code, notes, and snippets.

@rodrickbrown
Created July 10, 2014 02:31
Show Gist options
  • Save rodrickbrown/f95de537a90bd4134833 to your computer and use it in GitHub Desktop.
Save rodrickbrown/f95de537a90bd4134833 to your computer and use it in GitHub Desktop.
//
// main.swift
// Bukimur
//
// Created by Rodrick Brown on 7/8/14.
// Copyright (c) 2014 Rodrick Brown. All rights reserved.
//
import Foundation
class Sets {
var sets: [Dictionary<String, AnyObject>] = []
/*init(sets: [Dictionary<String, AnyObject>]) {
self.sets = sets
}*/
func validGroups() -> Bool {
if self.sets.count <= 0 {
return false
}
for (key, value) in enumerate(self.sets) {
println(value)
}
return true
}
}
class Bukimur {
let MAX_TILES = 104
var players = 0
var bag: [Dictionary<String, AnyObject>] = []
init(players: Int) {
self.players = players
}
func dealTiles(n: Int) -> [Dictionary<String, AnyObject>]{
var tiles: [Dictionary<String, AnyObject>] = []
for i in 0...n-1 {
tiles.append(self.bag[i])
self.bag.removeAtIndex(i)
}
return tiles
}
func shuffle<T>(var list: Array<T>) -> Array<T> {
for i in 0..<list.count {
let j = Int(arc4random_uniform(UInt32(list.count - i))) + i
list.insert(list.removeAtIndex(j), atIndex: i)
}
return list
}
func initalizeGame() -> Bool {
let decks = [0,1]
let colors = ["yellow", "black", "red", "blue"]
let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13]
for color in colors {
for deck in decks {
for num in numbers {
bag.append(["color": color, "deck": deck, "number": num])
}
}
}
self.bag = self.shuffle(self.bag)
return true
}
}
var game = Bukimur(players: 4)
if game.initalizeGame() {
//println(game.bag.count)
var myRack = game.dealTiles(14)
// println(myRack)
var playerSets: [Dictionary<String, AnyObject>] = [["color": "black", "deck": 0, "number": 7], ["color": "red", "deck": 0, "number": 7], ["color": "blue", "deck": 1, "number": 7]]
var c = Sets(playerSets)
//println(game.dealTiles(1))
//println(game.bag.count)
//Sets(self.bag)
}
else {
println("Error too many cards in deck " + String(game.bag.count))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment