Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 12135


Ignore:
Timestamp:
Dec 4, 2018, 1:56:55 PM (5 years ago)
Author:
samuelbl
Message:

Player functionalities added

Location:
code/branches/wagnis_HS18/src/modules/wagnis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc

    r12134 r12135  
    55#include <vector>
    66#include <string>
     7#include <cstdlib>
     8#include <ctime>
    79
    810namespace orxonox
     
    6062                    {   
    6163                        if (checkMove(SET_TROOPS_INITIAL)){
    62                             this->target_province->owner_ID = this->Player_ID;
     64                            this->target_province->setOwner_ID(this->Player_ID);
    6365                            this->target_province->setTroops(this->target_province->getTroops()+1);
    64                             orxout()<<"Province "<<this->target_province->ID<<" owned by Player "<<this->target_province->owner_ID<<" troops: "<<this->target_province->getTroops()<<endl;
     66                            orxout()<<"Province "<<this->target_province->getID()<<" owned by Player "<<this->target_province->getOwner_ID()<<" troops: "<<this->target_province->getTroops()<<endl;
    6567                            master->playerFinishedStageCallback(this);
    6668                        }else{
    6769                            orxout()<<"Sorry, someone already owns this provice"<<endl;
    6870                        }
     71                        //TODO: Set more troops to provinces before game begins
    6972
    7073                        break;
     
    7376                    case REINFORCEMENT_STAGE:
    7477                    {
    75                         if (checkMove(SET_TROOPS)){
    76                             this->target_province->setTroops(this->target_province->getTroops()+1);
    77                             orxout()<<"Province "<<this->target_province->ID<<" owned by Player "<<this->target_province->owner_ID<<" troops: "<<this->target_province->getTroops()<<endl;
     78                        int i = reinforcementCounter(); //i tells how many troops player gets
     79                        while (i > 0)
     80                        {
     81                            if (checkMove(SET_TROOPS))
     82                            {
     83                                this->target_province->setTroops(this->target_province->getTroops()+1);
     84                                orxout()<<"Province "<<this->target_province->getID()<<" owned by Player "<<this->target_province->getOwner_ID()<<" troops: "<<this->target_province->getTroops()<<endl;
     85                                --i;
     86                            }
    7887                        }
    79                            
     88
     89                        master->playerFinishedStageCallback(this);   
     90                       
    8091                        break;
    8192                    }
     
    89100                                {
    90101                                    //normal fight, 3 attackers, 2 defenders
     102                                    int att1 = dice();
     103                                    int att2 = dice();
     104                                    int att3 = dice();
     105                                    int def1 = dice();
     106                                    int def2 = dice();
     107                                    int attBest = best3(att1, att2, att3);
     108                                    int attSecond = second3(att1, att2, att3);
     109                                    int defBest = best2(def1, def2);
     110                                    int defSecond = second2(def1, def2);
     111
     112                                    if(defBest >= attBest)
     113                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     114                                    if (attBest > defBest)
     115                                        this->target_province->setTroops(this->target_province->getTroops()-1);
     116                                    if(defSecond >= attSecond)
     117                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     118                                    if (attSecond > defSecond)
     119                                        this->target_province->setTroops(this->target_province->getTroops()-1);
    91120                                }
    92121
     
    94123                                {
    95124                                    //2 attackers, 2 defenders
     125                                    int att1 = dice();
     126                                    int att2 = dice();
     127                                    int def1 = dice();
     128                                    int def2 = dice();
     129                                    int attBest = best2(att1, att2);
     130                                    int attSecond = second2(att1, att2);
     131                                    int defBest = best2(def1, def2);
     132                                    int defSecond = second2(def1, def2);
     133
     134                                    if(defBest >= attBest)
     135                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     136                                    if (attBest > defBest)
     137                                        this->target_province->setTroops(this->target_province->getTroops()-1);
     138                                    if(defSecond >= attSecond)
     139                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     140                                    if (attSecond > defSecond)
     141                                        this->target_province->setTroops(this->target_province->getTroops()-1);
    96142                                }
    97143
     
    99145                                {
    100146                                    //1 attacker, 2 defenders
    101                                 }
    102 
    103                                 //TODO: implement other cases
     147                                    int attBest = dice();
     148                                    int def1 = dice();
     149                                    int def2 = dice();
     150                                    int defBest = best2(def1, def2);
     151
     152                                    if(defBest >= attBest)
     153                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     154                                    if (attBest > defBest)
     155                                        this->target_province->setTroops(this->target_province->getTroops()-1);
     156                                }
     157
     158                                if((this->origin_province->getTroops() >= 4) && (this->target_province->getTroops() == 1))
     159                                {
     160                                    //3 attackers, 1 defender
     161                                    int att1 = dice();
     162                                    int att2 = dice();
     163                                    int att3 = dice();
     164                                    int defBest = dice();
     165                                    int attBest = best3(att1, att2, att3);
     166
     167                                    if(defBest >= attBest)
     168                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     169                                    if (attBest > defBest)
     170                                        this->target_province->setTroops(this->target_province->getTroops()-1);
     171                                }
     172
     173                                if((this->origin_province->getTroops() == 3) && (this->target_province->getTroops() == 1))
     174                                {
     175                                    //2 attackers, 1 defender
     176                                    int att1 = dice();
     177                                    int att2 = dice();
     178                                    int defBest = dice();
     179                                    int attBest = best2(att1, att2);
     180
     181                                    if(defBest >= attBest)
     182                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     183                                    if (attBest > defBest)
     184                                        this->target_province->setTroops(this->target_province->getTroops()-1);
     185                                }
     186
     187                                if((this->origin_province->getTroops() == 2) && (this->target_province->getTroops() == 1))
     188                                {
     189                                    //1 attacker, 1 defender
     190                                    int attBest = dice();
     191                                    int defBest = dice();
     192
     193                                    if(defBest >= attBest)
     194                                        this->origin_province->setTroops(this->origin_province->getTroops()-1);
     195                                    if (attBest > defBest)
     196                                        this->target_province->setTroops(this->target_province->getTroops()-1);
     197                                }
    104198                            }
    105199
    106200                            if (this->target_province->getTroops() == 0) //attacker won
    107201                            {
    108                                 this->target_province->owner_ID = this->Player_ID;
     202                                this->target_province->setOwner_ID(this->Player_ID);
    109203                                this->target_province->setTroops(this->origin_province->getTroops() - 1);
    110204                                this->origin_province->setTroops(1);
     
    120214                            this->target_province->setTroops(this->origin_province->getTroops()-1);
    121215                            this->origin_province->setTroops(1);
     216                            master->playerFinishedStageCallback(this);
    122217                        }
    123218                        break;
     
    221316        return false;
    222317    }
     318
     319    int WagnisPlayer::dice() //returns random integer in range [1, 2, 3, 4, 5, 6]
     320    {
     321        srand(time(NULL));
     322            return (rand()%6+1);
     323    }
     324
     325    int WagnisPlayer::best3(int a, int b, int c)
     326    {
     327        if(a >= b && a>= c)
     328            return a;
     329        if(b >= a && b>= c)
     330            return b;
     331        else   
     332            return c;
     333    }
     334
     335    int WagnisPlayer::best2(int a, int b)
     336    {
     337        if(a >= b)
     338            return a;
     339        else
     340            return b;
     341    }
     342
     343    int WagnisPlayer::second3(int a, int b, int c)
     344    {
     345        if((a >= b && a <= c)||(a <= b && a >= c))
     346            return a;
     347        if((b >= a && b <= c)||(b <= a && b >= c))
     348            return b;
     349        else   
     350            return c;
     351    }
     352
     353    int WagnisPlayer::second2(int a, int b)
     354    {
     355        if(a <= b)
     356            return a;
     357        else
     358            return b;   
     359    }
     360
     361    int WagnisPlayer::reinforcementCounter() //calculates how many troops a player gets at beginning of his turn
     362    {
     363       
     364        return 10;
     365        /*
     366        int counter = 0;
     367
     368        for (int i = 0; i <= 100; ++i)
     369        {
     370            if
     371        }
     372        */
     373
     374    }
    223375}
  • code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h

    r12134 r12135  
    4949        bool isNeighbour(WagnisProvince*, WagnisProvince*);
    5050        bool existPath(WagnisProvince*, WagnisProvince*);
     51        int dice();
     52        int best3(int, int, int);
     53        int best2(int, int);
     54        int second3(int, int, int);
     55        int second2(int, int);
     56        int reinforcementCounter();
    5157    };
    5258}
Note: See TracChangeset for help on using the changeset viewer.