<commit_before>//
//  CupShuffle.swift
//  ARPlay
//
//  Created by <NAME> on 7/22/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct Cup {
    var hasBall: Bool
    var position: Int
    var emptyPos: Bool
}

struct CupGame {
    var cups: [Cup]
}

class CupShuffle {
    
    var gameCups = CupGame(cups:[])
    
    init(cups: Int) {
        let postions = cups
        
        for i in 1...postions {
            //            if i == 1 {
            //                gameCups.cups.append(Cup(hasBall: false, position: i, emptyPos: true))
            //                continue
            //            }
            //
            //            if i == postions {
            //                gameCups.cups.append(Cup(hasBall: false, position: i, emptyPos: true))
            //                continue
            //            }
            
            gameCups.cups.append(Cup(hasBall: false, position: i, emptyPos: false, id: i))
        }
    }
    
    func AddBall() {
        gameCups.cups[self.RandomValidCupIndex(not: -1)].hasBall = true
    }
    
    func RandomValidCupIndex(not: Int?) -> Int {
        arc4random_stir()
        let theCup = Int(arc4random_uniform(UInt32(gameCups.cups.count)))
        
        if !gameCups.cups[theCup].emptyPos && theCup != not {
            return theCup
        } else {
            return RandomValidCupIndex(not: not)
        }
    }
    
    func ShuffleCups(times: Int) {
        for _ in 1...times {
            let moveFrom = RandomValidCupIndex(not: -1)
            let moveTo = RandomValidCupIndex(not: moveFrom)
            
            print ("MoveFrom: \(moveFrom) - MoveTo: \(moveTo)")
            
            ShuffleCupStep(fromPos: moveFrom, toPos: moveTo)
        }
    }
    
    func ShuffleCupStep(fromPos: Int, toPos: Int) {
        var arr = gameCups.cups
        arr.swapAt(fromPos, toPos)
        
        gameCups.cups = arr
        
        let cupElements = gameCups.cups.count - 1
        
        // update positons
        for i in 0...cupElements {
            gameCups.cups[i].position = i + 1
        }
        
        for i in 0...cupElements {
            printCupAt(i)
        }
        
        print ("\n\n")
    }
    
    func printCupAt(_ index: Int) {
        print ("Id: \(gameCups.cups[index].id) - " +
            "Position: \(gameCups.cups[index].position) - " +
            "Has Ball \(gameCups.cups[index].hasBall) - " +
            "Empty \(gameCups.cups[index].emptyPos)")
    }
}

<commit_msg>add ID to cup struct<commit_after>//
//  CupShuffle.swift
//  ARPlay
//
//  Created by <NAME> on 7/22/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct Cup {
    var hasBall: Bool
    var position: Int
    var emptyPos: Bool
    var id: Int
}

struct CupGame {
    var cups: [Cup]
}

class CupShuffle {
    
    var gameCups = CupGame(cups:[])
    
    init(cups: Int) {
        let postions = cups
        
        for i in 1...postions {
            //            if i == 1 {
            //                gameCups.cups.append(Cup(hasBall: false, position: i, emptyPos: true))
            //                continue
            //            }
            //
            //            if i == postions {
            //                gameCups.cups.append(Cup(hasBall: false, position: i, emptyPos: true))
            //                continue
            //            }
            
            gameCups.cups.append(Cup(hasBall: false, position: i, emptyPos: false, id: i))
        }
    }
    
    func AddBall() {
        gameCups.cups[self.RandomValidCupIndex(not: -1)].hasBall = true
    }
    
    func RandomValidCupIndex(not: Int?) -> Int {
        arc4random_stir()
        let theCup = Int(arc4random_uniform(UInt32(gameCups.cups.count)))
        
        if !gameCups.cups[theCup].emptyPos && theCup != not {
            return theCup
        } else {
            return RandomValidCupIndex(not: not)
        }
    }
    
    func ShuffleCups(times: Int) {
        for _ in 1...times {
            let moveFrom = RandomValidCupIndex(not: -1)
            let moveTo = RandomValidCupIndex(not: moveFrom)
            
            print ("MoveFrom: \(moveFrom) - MoveTo: \(moveTo)")
            
            ShuffleCupStep(fromPos: moveFrom, toPos: moveTo)
        }
    }
    
    func ShuffleCupStep(fromPos: Int, toPos: Int) {
        var arr = gameCups.cups
        arr.swapAt(fromPos, toPos)
        
        gameCups.cups = arr
        
        let cupElements = gameCups.cups.count - 1
        
        // update positons
        for i in 0...cupElements {
            gameCups.cups[i].position = i + 1
        }
        
        for i in 0...cupElements {
            printCupAt(i)
        }
        
        print ("\n\n")
    }
    
    func printCupAt(_ index: Int) {
        print ("Id: \(gameCups.cups[index].id) - " +
            "Position: \(gameCups.cups[index].position) - " +
            "Has Ball \(gameCups.cups[index].hasBall) - " +
            "Empty \(gameCups.cups[index].emptyPos)")
    }
}


{'fraction_non_alphanumeric': 0.11786624828397725, 'fraction_numerical': 0.00862914296920965, 'mean_word_length': 1.333028362305581, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6175840', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1625, 'n_words': 341}