Skip to content
Open

tp01 #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion Sources/swift_exercises.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum Type {
case rock
case steel
case water

}

// http://bulbapedia.bulbagarden.net/wiki/Damage_category
Expand Down Expand Up @@ -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?
Expand All @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions Tests/LinuxMain.swift

This file was deleted.

15 changes: 0 additions & 15 deletions Tests/swift-exercisesTests/swift_exercisesTests.swift

This file was deleted.

11 changes: 0 additions & 11 deletions wercker.yml

This file was deleted.