<s> import random <EOL> import numpy <EOL> import json <EOL> import math <EOL> _weapon = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> stance_mod = <NUM_LIT:1.0> <EOL> aim_difficulty = <NUM_LIT> <EOL> firearms_skill_mod = <NUM_LIT> <EOL> hit_certainty_mod = <NUM_LIT> <EOL> bullets = <NUM_LIT:10> <EOL> simulaton_ticks = <NUM_LIT:8> <EOL> def load_weapon ( weapon_file ) : <EOL> with open ( weapon_file , '<STR_LIT:r>' ) as wfile : <EOL> _weapon . update ( json . loads ( '<STR_LIT>' . join ( wfile . readlines ( ) ) ) ) <EOL> def velocity ( direction , speed ) : <EOL> rad = direction * ( math . pi / <NUM_LIT> ) <EOL> velocity = numpy . multiply ( numpy . array ( [ math . cos ( rad ) , math . sin ( rad ) ] ) , speed ) <EOL> return [ velocity [ <NUM_LIT:0> ] , - velocity [ <NUM_LIT:1> ] , <NUM_LIT:0> ] <EOL> def clip ( number , start , end ) : <EOL> return max ( start , min ( number , end ) ) <EOL> def bullet_trajectory ( bullet_pos , bullet_direction , ticks = simulaton_ticks ) : <EOL> bullet_velocity = velocity ( bullet_direction , <NUM_LIT:5> ) <EOL> for i in range ( ticks ) : <EOL> bullet_pos [ <NUM_LIT:0> ] += bullet_velocity [ <NUM_LIT:0> ] <EOL> bullet_pos [ <NUM_LIT:1> ] += bullet_velocity [ <NUM_LIT:1> ] <EOL> return bullet_pos <EOL> def simulate ( firearms_skill , recoil = <NUM_LIT:0.0> ) : <EOL> recoil = float ( recoil ) <EOL> bullet_direction = <NUM_LIT:0> <EOL> bullet_pos = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> bullet_velocity = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> _deviations = [ ] <EOL> _hits = <NUM_LIT:0> <EOL> for i in range ( bullets ) : <EOL> bullet_velocity = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> bullet_pos = [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> bullet_deviation = ( <NUM_LIT:1> - _weapon [ '<STR_LIT>' ] ) + recoil <EOL> deviation_mod = aim_difficulty * ( <NUM_LIT:1> - ( ( firearms_skill / <NUM_LIT> ) * firearms_skill_mod ) ) <EOL> deviation = ( bullet_deviation * aim_difficulty ) * deviation_mod <EOL> bullet_direction = random . uniform ( - deviation , deviation ) <EOL> _end_pos = bullet_trajectory ( bullet_pos , bullet_direction ) <EOL> _direction_deviation = abs ( bullet_direction ) <EOL> _target_hit_certainty = _direction_deviation / hit_certainty_mod <EOL> _hits += _target_hit_certainty <= <NUM_LIT:1> <EOL> _deviations . append ( _direction_deviation ) <EOL> return _hits / float ( bullets ) , _deviations <EOL> _path = '<STR_LIT>' <EOL> load_weapon ( _path ) <EOL> _accuracies = [ ] <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:10> + <NUM_LIT:1> ) : <EOL> print '<STR_LIT>' % i <EOL> for r in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> recoil = r / <NUM_LIT> <EOL> _accuracy , _deviations = simulate ( i , recoil = recoil ) <EOL> _accuracies . append ( _accuracy ) <EOL> print '<STR_LIT>' % ( recoil , _accuracy , sum ( _deviations ) / float ( len ( _deviations ) ) ) <EOL> print _weapon [ '<STR_LIT:name>' ] , '<STR_LIT>' , sum ( _accuracies ) / float ( len ( _accuracies ) ) </s>
