From 8723435e09122f6a26d418c2648adf7de57affee Mon Sep 17 00:00:00 2001 From: "Lenovo-PC\\ornela" Date: Fri, 24 Feb 2017 13:59:32 +0100 Subject: [PATCH 1/6] Test modif fichier --- Sources/swift_exercises.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index c51721d..f69308f 100644 --- a/Sources/swift_exercises.swift +++ b/Sources/swift_exercises.swift @@ -1,6 +1,6 @@ // http://bulbapedia.bulbagarden.net/wiki/Type enum Type { - case bug + case bug. case dark case dragon case electric From c22810be1105a3fb62d9a66e8bfb102a6e3cc42f Mon Sep 17 00:00:00 2001 From: Ornela Tchawou Date: Fri, 10 Mar 2017 15:39:24 +0100 Subject: [PATCH 2/6] corrige tipo --- Sources/swift_exercises.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index f69308f..c51721d 100644 --- a/Sources/swift_exercises.swift +++ b/Sources/swift_exercises.swift @@ -1,6 +1,6 @@ // http://bulbapedia.bulbagarden.net/wiki/Type enum Type { - case bug. + case bug case dark case dragon case electric From f17aece87294ce82f234ce8acfa9a9ba5c814aac Mon Sep 17 00:00:00 2001 From: Ornela Tchawou Date: Mon, 13 Mar 2017 12:44:49 +0100 Subject: [PATCH 3/6] exo1 --- Sources/swift_exercises.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index c51721d..a6f596e 100644 --- a/Sources/swift_exercises.swift +++ b/Sources/swift_exercises.swift @@ -124,6 +124,18 @@ 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 move = set() +move = [(1,"pound","touch ",Category.physical,Type.normal,40,100,35,2) , +(2,"karate chop","touch ",Category.physical,Type.fighting,50,100,25,2), +(8,"ice punch"," beautiful",Category.physical,Type.normal,75,100,15,2), +(19,"fly"," clever",Category.physical,Type.flying,90,95,15,2), +(14,"Swords dance"," beautiful",Category.status,Type.normal,20,0,0,2)] +let florizarre_specie = Species(001 , "florizarre", [],[move[1],move[2]],( Type.poison ,nil), (80,82,83,100,100,80),1) +let herbizarre_specie = Species(002, "herbizzare",[florizarre_specie],[move[3],move[2]],(Type.poison,nil),(60,62,63,80,80,60),2) +let espece = set() +espece = [ florizarre_specie,herbizarre_specie, +(003, bulbizarre, [florizarre_specie,herbizarre_specie],[move[0],move[3]],(Type.poison,nil),(45,49,49,65,65,45),3 ), +(119,poissiroy,[],[move[3],move[0]],(Type.water,nil),(140,87,63,63,76,65),4)] struct Pokemon { let nickname : String? From 4eb9372bf01138584c0cefe1c83c7cff1db29c86 Mon Sep 17 00:00:00 2001 From: Ornela Tchawou Date: Mon, 13 Mar 2017 23:07:54 +0100 Subject: [PATCH 4/6] =?UTF-8?q?exo=20deux=20rajout=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/swift_exercises.swift | 38 +++++++++++++------ Tests/LinuxMain.swift | 6 --- .../swift_exercisesTests.swift | 15 -------- wercker.yml | 11 ------ 4 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 Tests/LinuxMain.swift delete mode 100644 Tests/swift-exercisesTests/swift_exercisesTests.swift delete mode 100644 wercker.yml diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index a6f596e..ea6e7f9 100644 --- a/Sources/swift_exercises.swift +++ b/Sources/swift_exercises.swift @@ -124,18 +124,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 move = set() -move = [(1,"pound","touch ",Category.physical,Type.normal,40,100,35,2) , -(2,"karate chop","touch ",Category.physical,Type.fighting,50,100,25,2), -(8,"ice punch"," beautiful",Category.physical,Type.normal,75,100,15,2), -(19,"fly"," clever",Category.physical,Type.flying,90,95,15,2), -(14,"Swords dance"," beautiful",Category.status,Type.normal,20,0,0,2)] -let florizarre_specie = Species(001 , "florizarre", [],[move[1],move[2]],( Type.poison ,nil), (80,82,83,100,100,80),1) -let herbizarre_specie = Species(002, "herbizzare",[florizarre_specie],[move[3],move[2]],(Type.poison,nil),(60,62,63,80,80,60),2) -let espece = set() -espece = [ florizarre_specie,herbizarre_specie, -(003, bulbizarre, [florizarre_specie,herbizarre_specie],[move[0],move[3]],(Type.poison,nil),(45,49,49,65,65,45),3 ), -(119,poissiroy,[],[move[3],move[0]],(Type.water,nil),(140,87,63,63,76,65),4)] +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,prioriy: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,atack:87,defense:63,special_attack:63,special_defense:76,speed:65)) + struct Pokemon { let nickname : String? @@ -153,6 +152,21 @@ 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 { // } + let base :Stats(Species.base_values.hitpoints,Species.base_values.attack,Species.base_values.defense, + Species.base_values.special_attack,Species.base_values.special_defense,Species.base_values.speed) + let iv :Stats(individual_values.hitpoints,individual_values.attack,individual_values.defense, + individual_values.special_attack,individual_values.special_defense,individual_values.speed) + let ev :Stats(effort_values.hitpoints,effort_values.attack,effort_values.defense,effort_values.special_attack, + effort_values.special_defense,effort_values.speed) + + func other_stat(base:int , iv:int, ev:int ,levl : int)-> int{ + let ostat = (((base + iv )*2 + ev/4)*levl/100)+ levl +10 + return int(ostat) + } + fun point_vie(base:int , iv:int, ev:int ,levl : int)-> int{ + let pv = (((base + iv )*2 + ev/4)*levl/100)+5 + return int(pv) + } } struct Trainer { 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 From 7a60b6f22128112a33a70ddfcfd74b4586cde8db Mon Sep 17 00:00:00 2001 From: Ornela Tchawou Date: Sun, 19 Mar 2017 10:56:05 +0100 Subject: [PATCH 5/6] exercice 1 et 2 revus --- Sources/swift_exercises.swift | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index ea6e7f9..73e7ae9 100644 --- a/Sources/swift_exercises.swift +++ b/Sources/swift_exercises.swift @@ -152,21 +152,27 @@ 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 { // } + let base :Stats(Species.base_values.hitpoints,Species.base_values.attack,Species.base_values.defense, Species.base_values.special_attack,Species.base_values.special_defense,Species.base_values.speed) + let iv :Stats(individual_values.hitpoints,individual_values.attack,individual_values.defense, individual_values.special_attack,individual_values.special_defense,individual_values.speed) + let ev :Stats(effort_values.hitpoints,effort_values.attack,effort_values.defense,effort_values.special_attack, effort_values.special_defense,effort_values.speed) - func other_stat(base:int , iv:int, ev:int ,levl : int)-> int{ - let ostat = (((base + iv )*2 + ev/4)*levl/100)+ levl +10 - return int(ostat) - } - fun point_vie(base:int , iv:int, ev:int ,levl : int)-> int{ - let pv = (((base + iv )*2 + ev/4)*levl/100)+5 - return int(pv) + let 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_stat.hitpoint = int((((base[0] + iv[0] )*2 + ev[0]/4)*level/100)+ level +10) + let effective_stat.attact = effective_values( base[1], iv[1], ev[1] , level) + let effective_stat.defense= effective_values(base[2], iv[2], ev[2] ,level) + let effective_stat.special_attack = effective_values( base[3], iv[3], ev[3] , level) + let effective_stat.special_defense= effective_values( base[4], iv[4], ev[4] , level) + let effective_stat.speed = effective_values( base[5], iv[5], ev[5] , level) } struct Trainer { From 4f14606d9d70767470a4a9314930a23e933a05cf Mon Sep 17 00:00:00 2001 From: Ornela Tchawou Date: Sun, 19 Mar 2017 17:27:17 +0100 Subject: [PATCH 6/6] exo 3 rajoute --- Sources/swift_exercises.swift | 49 +++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/Sources/swift_exercises.swift b/Sources/swift_exercises.swift index 73e7ae9..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 @@ -125,7 +126,7 @@ func ==(lhs: Species, rhs: Species) -> Bool { // 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,prioriy: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) @@ -133,7 +134,7 @@ let switch_move = Move(id:14,name:"Swords dance",description:" beautiful",catego 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,atack:87,defense:63,special_attack:63,special_defense:76,speed:65)) +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 { @@ -153,26 +154,22 @@ struct Pokemon { // var effective_stats : Stats { // } - let base :Stats(Species.base_values.hitpoints,Species.base_values.attack,Species.base_values.defense, - Species.base_values.special_attack,Species.base_values.special_defense,Species.base_values.speed) - let iv :Stats(individual_values.hitpoints,individual_values.attack,individual_values.defense, - individual_values.special_attack,individual_values.special_defense,individual_values.speed) + 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 - let ev :Stats(effort_values.hitpoints,effort_values.attack,effort_values.defense,effort_values.special_attack, - effort_values.special_defense,effort_values.speed) - let effective_stats : Stats - func effective_values(b:int , i:int, e:int , levl : int)-> int{ + 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) + - return int((((b + i)*2 + e/4)*levl/100)+5) - } - let effective_stat.hitpoint = int((((base[0] + iv[0] )*2 + ev[0]/4)*level/100)+ level +10) - let effective_stat.attact = effective_values( base[1], iv[1], ev[1] , level) - let effective_stat.defense= effective_values(base[2], iv[2], ev[2] ,level) - let effective_stat.special_attack = effective_values( base[3], iv[3], ev[3] , level) - let effective_stat.special_defense= effective_values( base[4], iv[4], ev[4] , level) - let effective_stat.speed = effective_values( base[5], iv[5], ev[5] , level) } struct Trainer { @@ -187,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