diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index c51721d..073d9ec 100644 --- a/Sources/swift_exercises.swift +++ b/Sources/swift_exercises.swift @@ -18,6 +18,7 @@ enum Type { case rock case steel case water + } // http://bulbapedia.bulbagarden.net/wiki/Damage_category @@ -124,6 +125,17 @@ func ==(lhs: Species, rhs: Species) -> Bool { // TODO: create some species // Do you use an enum, a map or constants/variables? // http://bulbapedia.bulbagarden.net/wiki/List_of_Pokémon_by_National_Pokédex_number +let pound_move = Move(id:1,name:"pound",description:"touch ",category:Category.physical,type:Type.normal,power:40,accuracy:100,powerpoints:35,priority:0) +let karate_move = Move(id:2,name:"karate chop",description:"touch ",category:Category.physical,type:Type.fighting,power:50,accuracy:100,powerpoints:25,priority:0) +let ice_punch_move = Move(id:8,name:"ice punch",description:" beautiful",category:Category.physical,type:Type.normal,power:75,accuracy:100,powerpoints:15,priority:0) +let fly_move = Move(id:19,name:"fly",description:" clever",category:Category.physical,type:Type.flying,power:90,accuracy:95,powerpoints:15,priority:0) +let switch_move = Move(id:14,name:"Swords dance",description:" beautiful",category:Category.status,type:Type.normal,power:20,accuracy:0,powerpoints:0,priority:0) + +let florizarre_specie = Species(id:001 ,name: "florizarre", evolutions:[],attacks:[pound_move,switch_move],type:( Type.poison ,nil), base_values:Stats(hitpoints:80,attack:82,defense:83,special_attack:100,special_defense:100,speed:80)) +let herbizarre_specie = Species(id:002, name:"herbizzare",evolutions:[florizarre_specie],attacks:[karate_move,fly_move],type:(Type.poison,nil),base_values:Stats(hitpoints:60,attack:62,defense:63,special_attack:80,special_defense:80,speed:60)) +let bulbizarre_specie = Species(id:003, name:"bulbizarre", evolutions:[florizarre_specie,herbizarre_specie],attacks:[pound_move,fly_move],type:(Type.poison,nil),base_values:Stats(hitpoints:45,attack:49,defense:49,special_attack:65,special_defense:65,speed:45) ) +let poissiroy_specie = Species(id:119,name:"poissiroy",evolutions:[],attacks:[switch_move ,pound_move],type:(Type.water,nil),base_values:Stats(hitpoints:140,attack:87,defense:63,special_attack:63,special_defense:76,speed:65)) + struct Pokemon { let nickname : String? @@ -141,6 +153,23 @@ struct Pokemon { // https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html#//apple_ref/doc/uid/TP40014097-CH14-ID259 // var effective_stats : Stats { // } + + + func effective_values(b:Int , i:Int, e:Int , levl : Int)-> Int{ + + return Int((((b + i)*2 + e/4)*levl/100) + 5) + } + let effective_stats = Stats.self + + + effective_stats.hitpoints = (((( species.base_values.hitpoints + individual_values.hitpoints )*2 + effort_values.hitpoints/4)*level/100) + level + 10) + effective_stats.attack = effective_values( species.base_values.attack, individual_values.attack, effort_values.attack , level) + effective_stats.defense = effective_values(species.base_values.defense, individual_values.defense, effort_values.defense ,level) + effective_stats.special_attack = effective_values( species.base_values.special_attack, individual_values.special_attack, individual_values.special_attack , level) + effective_stats.special_defense = effective_values( species.base_values.special_defense, individual_values.special_defense, effort_values.special_defense , level) + effective_stats.speed = effective_values( species.base_values.speed, individual_values.speed, effort_values.speed , level) + + } struct Trainer { @@ -155,9 +184,23 @@ struct Environment { // http://bulbapedia.bulbagarden.net/wiki/Type/Type_chart func typeModifier(attacking: Type, defending : Type) -> Double { // TODO: encode type/type chart - return 1 + typealias Modif = ( typ :Type , typ:Type,coeff :Double) + var coeff_modif = [Modif]() + coeff_modif = [(.normal, .normal, 1), (.normal, .fighting, 1), (.normal, .flying, 1), (.normal, .poison, 1), + (.normal,.ground, 1), (.normal, .rock, 0.5), (.normal, .bug, 1), (.normal, .ghost, 0), (.normal, .steel, 0.5), + (.normal, .fire, 1), (.normal, .water, 1), (.normal, .grass, 1), (.normal, .electric, 1), (.normal, .psychic, 1), + (.normal, .ice, 1), (.normal, .dragon, 1), (.normal, .dark, 1), (.normal, .fairy, 1), (.fighting, .normal, 2), + (.fighting, .fighting, 1), (.fighting, .flying, 0.5), (.fighting, .poison, 0.5), (.fighting, .ground, 0.5), (.fighting, .rock, 2)] +for i in 0 ... 23 { + if (attacking == coeff_modif[i].typ) && (defending == coeff_modif[i].typ) { + return Double ( coeff_modif[i].coeff) + } } + + } + + // http://bulbapedia.bulbagarden.net/wiki/Damage func damage(environment : Environment, pokemon: Pokemon, move: Move, target: Pokemon) -> Int { // TODO diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index 7ae448c..0000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,6 +0,0 @@ -import XCTest -@testable import swift_exercisesTests - -XCTMain([ - testCase(swift_exercisesTests.allTests), -]) diff --git a/Tests/swift-exercisesTests/swift_exercisesTests.swift b/Tests/swift-exercisesTests/swift_exercisesTests.swift deleted file mode 100644 index eab452c..0000000 --- a/Tests/swift-exercisesTests/swift_exercisesTests.swift +++ /dev/null @@ -1,15 +0,0 @@ -import XCTest -@testable import swift_exercises - -class swift_exercisesTests: XCTestCase { - - func test_typeModifier() { - XCTAssertEqual(typeModifier(attacking: Type.normal, defending: Type.normal), 1, "normal/normal should be 1") - } - - static var allTests : [(String, (swift_exercisesTests) -> () throws -> Void)] { - return [ - ("Type/Type modifiers", test_typeModifier), - ] - } -} diff --git a/wercker.yml b/wercker.yml deleted file mode 100644 index 420c888..0000000 --- a/wercker.yml +++ /dev/null @@ -1,11 +0,0 @@ -box: swift -build: - steps: - - script: - name: build - code: | - swift build - - script: - name: test - code: | - swift test