-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.cc
93 lines (52 loc) · 2.21 KB
/
sample.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <array>
#include <algorithm>
#include "chance.hh"
#include "combatant.hh" // parsec::combatant_t
using namespace std; // standard library
typedef array< parsec::combatant_t, 0x3 > battle_line_t;
enum role_t { defender, attacker };
//-----------------------------------------------------------------------------
combat_t generate_combat_type( ) {
static int count = 0x0;
return make_pair( chance::number::single(), ++count );
}; // end
struct combat_victor_t {
inline bool operator() ( const parsec::combatant_t& one, const parsec::combatant_t& two ) {
return one.attack > two.attack;
}; // end operator()
}; // end combat_victor_t
//-----------------------------------------------------------------------------
battle_line_t generate_battle_line( role_t role ) {
static parsec::combatant_t empty;
battle_line_t results( {
generate_combat_type(), generate_combat_type(),
( role == defender ? empty : generate_combat_type() ) } );
sort( results.begin(), results.end(), combat_victor_t() );
return results;
}; // end generate
//-----------------------------------------------------------------------------
void dump( const battle_line_t& bl ) {
for( auto iter : bl ) cout << iter.first << " : " << iter.second << endl;
cout << endl;
}; // end dump
//-----------------------------------------------------------------------------
void battle( battle_line_t& at, battle_line_t& def ) {
if ( def[ 0 ].first >= at[ 0 ].first )
cout << "Attacker lost one " << at[ 0 ].second << endl;
else cout << "Defender lost one " << def[ 0 ].second << endl;
if ( def[ 1 ].first >= at[ 1 ].first )
cout << "Attacker lost one " << at[ 1 ].second << endl;
else cout << "Defender lost one " << def[ 1 ].second << endl;
}; // end battle
// Entry into application
//-----------------------------------------------------------------------------
int main( int, char*[] ) {
battle_line_t attackers( generate_battle_line( attacker ) );
battle_line_t defenders( generate_battle_line( defender ) );
cout << "attacker fleet:" << endl;
dump( attackers );
cout << "defender fleet:" << endl;
dump( defenders );
battle( attackers, defenders );
}; // end main