@popsoftheyear:
I'm satisfied with the solution I have right now. Most important: I understand my code even after 3 days of absence.
the assignment is:
deck_BoF[0].LoadResource("./deck/BoF_Fireball.txt"); deck_BoF[0].SetAction(ActionBoF_Fireball); deck_BoF[0].SetTryAction(TryActionBoF_Fireball);
the implementation is:
void (*Action) (void); float (*TryAction) (void);
and:
inline void SetAction(void (*_fcn_handle)(void)) { Action = (*_fcn_handle); } inline void SetTryAction(float (*_fcn_handle)(void)) { TryAction = (*_fcn_handle); }
It's possible to call the functions from outside, because they are member functions from class "card". It was easier to do it this way, than to use virtual functions.
See the implementation inside the AI function part, which is used to balance the chances, which card to be played. It works without memory leak and increasment.
if (play_with_cards){ //Maximum of three active cards available //Chance, which card to be played best std::vector<int> index; index = player[active_player].GetActiveCards(); std::vector<float> chance; for (int iCard = 0; iCard < (int)index.size(); ++iCard){ active_card = index[iCard]; chance.push_back(player[active_player].deck[index[iCard]]->TryAction()); } if (chance.size() > 0) { //Which card has highest chance to be played? int best = Math::MaxFIndex(chance); //Play Card if Chance higher than 60% if (chance[best] >= 60){ effect_player = active_player; effect_card = index[best]; active_card = index[best]; Action(); } } }
The Action is used by AI and by player, therefore I needed to capsulate it:
//------------------------------------------------------------------------------void Action(void){//------------------------------------------------------------------------------ if (player[active_player].deck[active_card]->Action != NULL && !player[active_player].deck[active_card]->IsBlocked()){ player[active_player].deck[active_card]->Action(); if (player[active_player].deck[active_card]->IsTagged()) player[active_player].deck[active_card]->SetBlock(true); }}
@Jason:
Goal of Cycle is to occupy the most fields. You see the red nodes at the crossings? Those have to be occupied by tokens. The player with the most occupied tokens around a field occupies the field. If the number of player and enemy tokens are the same, the field is freed. The cards can be used to delete enemy nodes, steal enemy nodes, reduce enemy points (needed to play cards), modify card status (block, discard, draw new) or similar stuff. To increase the strategic part, I need to do a bit more balancing. The cards are finished in design, but need to be improved a bit. Right now, Brotherhood of Flame is a bit too strong. However, the computer is able to play itself.