Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 37.16 KB | None | 0 0
  1. /*
  2.  *  Game.c
  3.  *  1917 v2.0
  4.  *  Add to and change this file as you wish to implement the
  5.  *  interface functions in Game.h
  6.  *
  7.  *  Created by Richard Buckland on 20/04/11.
  8.  *  Copyright 2011 Licensed under Creative Commons SA-BY-NC 3.0.  
  9.  *
  10.  */
  11.    
  12. //By Anne, Ben, Nat, Sheryl, Yere
  13. //12 MAY 2011
  14.    
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <assert.h>
  19.    
  20. #include "Game.h"
  21.    
  22. #define EAST 0
  23. #define SOUTH_EAST 1
  24. #define SOUTH_WEST 2
  25. #define WEST 3
  26. #define NORTH_WEST 4
  27. #define NORTH_EAST 5
  28.    
  29. #define NUM_STUDENT_TYPES 6
  30.    
  31. #define NUM_DIRECTIONS 6
  32.    
  33. #define NUM_VERTICES 54
  34. #define NUM_ARCS 72
  35.    
  36. #define NUM_RETRAININGCENTRES 9
  37.    
  38. //-------Data structures
  39.    
  40. typedef struct _playerCodes {
  41.    int playersARC; //code for the given players' arcs
  42.    int playersCampus; //code for the given players' campuses
  43.    int playersGO8; //code for the given players' GO8s
  44. } playerCodes;
  45.    
  46. typedef struct _vertex {
  47.    int x; //horizontal axis -
  48.    int y; //axis facing the same way as a forward slash
  49.    int z; // axis facing the same way as a backslash
  50.    int content;
  51. } vertex;
  52.    
  53. typedef struct _arc {
  54.    int leftPoint; //the leftmost point the arc is on
  55.    int rightPoint; //the rightmost point the arc is on
  56.    int content;
  57. } arc;
  58.    
  59. typedef struct _region {
  60.    int x;
  61.    int y;
  62.    int z;
  63.    int diceNumber;
  64.    int discipline;
  65. } region;
  66.    
  67. typedef struct _retrainingCentre {
  68.    int arc; //The arc the retraining centre is on
  69.    int retrainingType; //2 or 3
  70.    int discipline; //The discipline of student it produces (type 2 only)
  71. } retrainingCentre;
  72.    
  73. typedef struct _game {
  74. //Current status
  75.    int currentPlayer;
  76.    int currentTurn;
  77.    int currentDice;
  78.      
  79. //'Most' status
  80.    int mostARCs;
  81.    int mostPubs;  
  82.      
  83. //Player stats
  84.    int patents[NUM_UNIS+1];
  85.    int publications[NUM_UNIS+1];
  86.    int KPI[NUM_UNIS+1];
  87.    //An array of size 3, each element is another array of size 6  
  88.    //(stores how many of each student a uni has)
  89.    int students[NUM_UNIS+1][NUM_STUDENT_TYPES];  
  90.    
  91. //An array of region 'structs'
  92.    region regions[NUM_REGIONS];
  93.      
  94. //An array of retraining centres
  95.    retrainingCentre retrainingCentres[NUM_RETRAININGCENTRES];
  96.      
  97. //Vertices and arcs
  98.    vertex vertices[NUM_VERTICES];
  99.    arc arcs[NUM_ARCS];
  100.    
  101. } game;
  102.    
  103. //---------------Shared helper functions
  104. //returns a value >NUM_VERTICES if path invalid
  105. static int getVertexID (Game g, path pathToVertex);  
  106. //returns a value >NUM_ARCS if path invalid
  107. static int getARCID (Game g, path pathToEdge);  
  108. //set up the #define of the ARC/GO8/Campus for the player
  109. static playerCodes getPlayerCodes (Game g, int player);  
  110. //convert path to coordinate
  111. static void shiftCoordinate (path pathTo, int *x, int *y, int*z);  
  112.    
  113. static int getVertexID (Game g, path pathToVertex) {
  114.    int vx, vy, vz;
  115.    int theVertex;
  116.    int i;
  117.    theVertex = NUM_VERTICES+1; //Set it to an invalid vertex initially
  118.    shiftCoordinate(pathToVertex, &vx, &vy, &vz);
  119.    i = 0;
  120.    //once the vertex is found or searched through all, exit while
  121.    while ((i < NUM_VERTICES) && (theVertex > NUM_VERTICES)) {
  122.       if ((vx == g->vertices[i].x) && (vy == g->vertices[i].y) &&  
  123.           (vz == g->vertices[i].z)) {
  124.          theVertex = i;
  125.       }
  126.       i++;
  127.    }
  128.    return theVertex;
  129. }
  130.    
  131. static int getARCID (Game g, path pathToEdge) {
  132.    int theARC;
  133.    int firstVertex, secondVertex;
  134.    path backPath;
  135.    int i;
  136.    theARC = NUM_ARCS+1; //Set it to an invalid arc initially
  137.    firstVertex = getVertexID (g, pathToEdge);
  138.    memcpy(backPath, pathToEdge, strlen(pathToEdge)+1);
  139.    strcat(backPath, "B");
  140.    secondVertex = getVertexID (g, backPath);
  141.    //printf("first vertex is %s\n", pathToEdge);
  142.    //printf("second vertex is %s", backPath);
  143.    i = 0;
  144.    //once the arc is found or searched through all the arcs, exit while
  145.    while ((i < NUM_ARCS) && (theARC > NUM_ARCS)) {
  146.       if (((g->arcs[i].leftPoint == firstVertex) &&  
  147.           (g->arcs[i].rightPoint == secondVertex))
  148.           ||((g->arcs[i].rightPoint == firstVertex) &&  
  149.           (g->arcs[i].leftPoint == secondVertex))) {
  150.          theARC = i;
  151.       }
  152.       i++;
  153.    }
  154.    return theARC;
  155. }
  156.    
  157. static playerCodes getPlayerCodes (Game g, int player) {
  158.    playerCodes codes;
  159.    codes.playersARC = 0;
  160.    codes.playersCampus = 0;
  161.    codes.playersGO8 = 0;
  162.    if (player == UNI_A) {
  163.       codes.playersARC = ARC_A;
  164.       codes.playersCampus = CAMPUS_A;
  165.       codes.playersGO8 = GO8_A;
  166.    } else if (player == UNI_B) {
  167.       codes.playersARC = ARC_B;
  168.       codes.playersCampus = CAMPUS_B;
  169.       codes.playersGO8 = GO8_B;
  170.    } else if (player == UNI_C) {
  171.      codes.playersARC = ARC_C;
  172.      codes.playersCampus = CAMPUS_C;
  173.      codes.playersGO8 = GO8_C;
  174.    } else {
  175.      codes.playersARC = 0;
  176.      codes.playersCampus = 0;
  177.      codes.playersGO8 = 0;
  178.    }
  179.    return codes;
  180. }
  181.    
  182. //coordinate/path system
  183. static void shiftCoordinate(path pathTo, int *x, int *y, int *z) {  
  184.    int facingPath;
  185.    int i;
  186.    //initialise start position
  187.    *x = 0;
  188.    *y = 2;
  189.    *z = 7;
  190.    //initial facing position
  191.    facingPath = SOUTH_EAST;
  192.    i = 0;
  193.    while ((pathTo[i] != '\0') && (i < PATH_LIMIT)) {
  194.       if (pathTo[i] == 'L') {
  195.          facingPath = ((facingPath - 1) % NUM_DIRECTIONS);
  196.          while (facingPath < 0) {
  197.             facingPath = (facingPath + NUM_DIRECTIONS)% NUM_DIRECTIONS;
  198.          }
  199.       } else if (pathTo[i] == 'R') {
  200.          facingPath = ((facingPath + 1) % NUM_DIRECTIONS);
  201.       } else if (pathTo[i] == 'B') {
  202.          facingPath = ((facingPath + 3) % NUM_DIRECTIONS);
  203.       }
  204.        
  205.       if (facingPath == EAST) {
  206.          *y+=1;
  207.          *z+=1;
  208.       } else if (facingPath == SOUTH_EAST) {
  209.          *x+=1;
  210.          *y+=1;
  211.       } else if (facingPath == SOUTH_WEST) {
  212.          *x+=1;
  213.          *z-=1;
  214.       } else if (facingPath == WEST) {
  215.          *y-=1;
  216.          *z-=1;
  217.       } else if (facingPath == NORTH_WEST) {
  218.          *x-=1;
  219.          *y-=1;
  220.       } else if (facingPath == NORTH_EAST) {
  221.          *x-=1;
  222.          *z+=1;
  223.       }
  224.    i++;
  225.    }
  226. }
  227.    
  228. //---------'Setters'
  229. Game newGame (int discipline[], int dice[]) {
  230.     Game g = malloc(sizeof(game));
  231.     int uni, student;
  232.     g->currentTurn = -1;
  233.     g->currentDice = 0;
  234.     g->currentPlayer = NO_ONE;
  235.     g->mostARCs = NO_ONE;
  236.     g->mostPubs = NO_ONE;
  237.     uni = UNI_A;
  238.     student = STUDENT_THD;
  239.     while (uni <= UNI_C) {
  240.         student = 0;
  241.         while (student < NUM_STUDENT_TYPES) {
  242.             g->students[uni][student] = 0;
  243.             student++;
  244.         }
  245.         g->patents[uni] = 0;
  246.         g->publications[uni] = 0;
  247.         g->KPI[uni] = 24;
  248.         uni++;
  249.     }
  250.      
  251. //Set all the regions - 19 times
  252.     region allRegions[NUM_REGIONS] = {
  253.    //blue 0
  254.    {
  255.       .x = 3,
  256.       .y = 1,
  257.       .z = 3,
  258.    },
  259.    //red 1
  260.    {
  261.       .x = 5,
  262.       .y = 2,
  263.       .z = 2,
  264.    },
  265.    //light blue 2
  266.    {
  267.       .x = 7,
  268.       .y = 3,
  269.       .z = 1,
  270.    },
  271.    //yellow 3
  272.    {
  273.       .x = 2,
  274.       .y = 2,
  275.       .z = 5,
  276.    },
  277.    //green 4
  278.    {
  279.       .x = 4,
  280.       .y = 3,
  281.       .z = 4,
  282.    } ,
  283.    //purple 5
  284.    {
  285.       .x = 6,
  286.       .y = 4,
  287.       .z = 3,
  288.    },
  289.    //blue 6
  290.   {
  291.       .x = 8,
  292.       .y = 5,
  293.       .z = 2,
  294.    },
  295.    //red 7
  296.    {
  297.       .x = 1,
  298.       .y = 3,
  299.       .z = 7,
  300.    },
  301.    //light blue 8
  302.    {
  303.       .x = 3,
  304.       .y = 4,
  305.       .z = 6,
  306.    },
  307.    //yellow 9
  308.    {
  309.       .x = 5,
  310.       .y = 5,
  311.       .z = 5,
  312.    },
  313.    //green 10
  314.    {
  315.       .x = 7,
  316.       .y = 6,
  317.       .z = 4,
  318.    },
  319.    //purple 11
  320.    {
  321.       .x = 9,
  322.       .y = 7,
  323.       .z = 3,
  324.    },
  325.    //blue 12
  326.    {
  327.       .x = 2,
  328.       .y = 5,
  329.       .z = 8,
  330.    },
  331.    //red 13
  332.    {
  333.       .x = 4,
  334.       .y = 6,
  335.       .z = 7,
  336.    },
  337.    //light blue 14
  338.    {
  339.       .x = 6,
  340.       .y = 7,
  341.       .z = 6,
  342.    },
  343.    //yellow 15
  344.    {
  345.       .x = 8,
  346.       .y = 8,
  347.       .z = 5,
  348.    },
  349.    //green 16
  350.    {
  351.       .x = 3,
  352.       .y = 7,
  353.       .z = 9,
  354.    },
  355.    //purple 17
  356.    {
  357.       .x = 5,
  358.       .y = 8,
  359.       .z = 8,
  360.    },
  361.    //blue 18
  362.    {
  363.       .x = 7,
  364.       .y = 9,
  365.       .z = 7,
  366.    },
  367.    };
  368.      
  369.    //Copy this set of regions into game struct
  370.    int i;
  371.    i = 0;
  372.    while (i < NUM_REGIONS) {
  373.       g->regions[i] = allRegions[i];
  374.       i++;
  375.    }
  376.    //Set all the dice and disciplines for the regions
  377.    i = 0;
  378.    while (i < NUM_REGIONS) {
  379.       g->regions[i].diceNumber = dice[i];
  380.       g->regions[i].discipline = discipline[i];
  381.       i++;
  382.    }
  383.      
  384. //Set all the vertices. Also set up the initial campuses for the unis
  385.    vertex allVertices[NUM_VERTICES] = {
  386.     //1
  387.    {
  388.       .x = 0,
  389.       .y = 2,
  390.       .z = 7,
  391.       .content = CAMPUS_A
  392.    },
  393.     //2
  394.    {
  395.       .x = 0,
  396.       .y = 3,
  397.       .z = 8,
  398.       .content = VACANT_VERTEX
  399.    },
  400.     //3
  401.    {
  402.       .x = 1,
  403.       .y = 4,
  404.       .z = 8,
  405.       .content = VACANT_VERTEX
  406.    },
  407.     //4
  408.    {
  409.       .x = 1,
  410.       .y = 5,
  411.       .z = 9,
  412.       .content = VACANT_VERTEX
  413.    },
  414.     //5
  415.    {
  416.       .x = 2,
  417.       .y = 6,
  418.       .z = 9,
  419.       .content = VACANT_VERTEX
  420.    },
  421.     //6
  422.    {
  423.       .x = 2,
  424.       .y = 7,
  425.       .z = 10,
  426.       .content = CAMPUS_C
  427.    },
  428.     //7
  429.    {
  430.       .x = 3,
  431.       .y = 8,
  432.       .z = 10,
  433.       .content = VACANT_VERTEX
  434.    },
  435.     //8
  436.    {
  437.       .x = 4,
  438.       .y = 8,
  439.       .z = 9,
  440.       .content = VACANT_VERTEX
  441.    },
  442.     //9  
  443.    {
  444.       .x = 5,
  445.       .y = 9,
  446.       .z = 9,
  447.       .content = VACANT_VERTEX
  448.    },
  449.    //10
  450.    {
  451.       .x = 6,
  452.       .y = 9,
  453.       .z = 8,
  454.       .content = VACANT_VERTEX
  455.    },
  456.     //11  
  457.    {
  458.       .x = 7,
  459.       .y = 10,
  460.       .z = 8,
  461.       .content = CAMPUS_B
  462.    },  
  463.    //12
  464.    {
  465.       .x = 8,
  466.       .y = 10,
  467.       .z = 7,
  468.       .content = VACANT_VERTEX
  469.    },
  470.    //13
  471.    {
  472.       .x = 8,
  473.       .y = 9,
  474.       .z = 6,
  475.       .content = VACANT_VERTEX
  476.    },
  477.    //14
  478.    {
  479.       .x = 9,
  480.       .y = 9,
  481.       .z = 5,
  482.       .content = VACANT_VERTEX
  483.    },
  484.    //15
  485.    {
  486.       .x = 9,
  487.       .y = 8,
  488.       .z = 4,
  489.       .content = VACANT_VERTEX
  490.    },
  491.     //16
  492.    {
  493.       .x = 10,
  494.       .y = 8,
  495.       .z = 3,
  496.       .content = CAMPUS_A
  497.    },
  498.    //17
  499.    {
  500.       .x = 10,
  501.       .y = 7,
  502.       .z = 2,
  503.       .content = VACANT_VERTEX
  504.    },
  505.    //18
  506.    {
  507.       .x = 9,
  508.       .y = 6,
  509.       .z = 2,
  510.       .content = VACANT_VERTEX
  511.    },
  512.    //19
  513.    {
  514.       .x = 9,
  515.       .y = 5,
  516.       .z = 1,
  517.       .content = VACANT_VERTEX
  518.    },
  519.    //20
  520.    {
  521.       .x = 8,
  522.       .y = 4,
  523.       .z = 1,
  524.       .content = VACANT_VERTEX
  525.    },
  526.     //21
  527.    {
  528.       .x = 8,
  529.       .y = 3,
  530.       .z = 0,
  531.       .content = CAMPUS_C
  532.    },
  533.    //22
  534.    {
  535.       .x = 7,
  536.       .y = 2,
  537.       .z = 0,
  538.       .content = VACANT_VERTEX
  539.    },
  540.    //23
  541.    {
  542.       .x = 6,
  543.       .y = 2,
  544.       .z = 1,
  545.       .content = VACANT_VERTEX
  546.    },
  547.    //24
  548.    {
  549.       .x = 5,
  550.       .y = 1,
  551.       .z = 1,
  552.       .content = VACANT_VERTEX
  553.    },
  554.    //25
  555.    {
  556.       .x = 4,
  557.       .y = 1,
  558.       .z = 2,
  559.       .content = VACANT_VERTEX
  560.    },
  561.     //26
  562.    {
  563.       .x = 3,
  564.       .y = 0,
  565.       .z = 2,
  566.       .content = CAMPUS_B
  567.    },
  568.    //27
  569.    {
  570.       .x = 2,
  571.       .y = 0,
  572.       .z = 3,
  573.       .content = VACANT_VERTEX
  574.    },
  575.    //28
  576.    {
  577.       .x = 2,
  578.       .y = 1,
  579.       .z = 4,
  580.       .content = VACANT_VERTEX
  581.    },
  582.    //29
  583.    {
  584.       .x = 1,
  585.       .y = 1,
  586.       .z = 5,
  587.       .content = VACANT_VERTEX
  588.    },
  589.    //30
  590.    {
  591.       .x = 1,
  592.       .y = 2,
  593.       .z = 6,
  594.       .content = VACANT_VERTEX
  595.    },
  596.    //31
  597.    {
  598.       .x = 2,
  599.       .y = 3,
  600.       .z = 6,
  601.       .content = VACANT_VERTEX
  602.    },
  603.    //32
  604.    {
  605.       .x = 2,
  606.       .y = 4,
  607.       .z = 7,
  608.       .content = VACANT_VERTEX
  609.    },
  610.    //33
  611.    {
  612.       .x = 3,
  613.       .y = 5,
  614.       .z = 7,
  615.       .content = VACANT_VERTEX
  616.    },
  617.    //34
  618.    {
  619.       .x = 3,
  620.       .y = 6,
  621.       .z = 8,
  622.       .content = VACANT_VERTEX
  623.    },
  624.    //35
  625.    {
  626.       .x = 4,
  627.       .y = 7,
  628.       .z = 8,
  629.       .content = VACANT_VERTEX
  630.    },
  631.    //36
  632.    {
  633.       .x = 5,
  634.       .y = 7,
  635.       .z = 7,
  636.       .content = VACANT_VERTEX
  637.    },
  638.    //37
  639.    {
  640.       .x = 6,
  641.       .y = 8,
  642.       .z = 7,
  643.       .content = VACANT_VERTEX
  644.    },
  645.    //38
  646.    {
  647.       .x = 7,
  648.       .y = 8,
  649.       .z = 6,
  650.       .content = VACANT_VERTEX
  651.    },
  652.    //39
  653.    {
  654.       .x = 7,
  655.       .y = 7,
  656.       .z = 5,
  657.       .content = VACANT_VERTEX
  658.    },
  659.    //40
  660.    {
  661.       .x = 8,
  662.       .y = 7,
  663.       .z = 4,
  664.       .content = VACANT_VERTEX
  665.    },
  666.    //41
  667.    {
  668.       .x = 8,
  669.       .y = 6,
  670.       .z = 3,
  671.       .content = VACANT_VERTEX
  672.    },
  673.    //42
  674.    {
  675.       .x = 7,
  676.       .y = 5,
  677.       .z = 3,
  678.       .content = VACANT_VERTEX
  679.    },
  680.    //43
  681.    {
  682.       .x = 7,
  683.       .y = 4,
  684.       .z = 2,
  685.       .content = VACANT_VERTEX
  686.    },
  687.    //44
  688.    {
  689.       .x = 6,
  690.       .y = 3,
  691.       .z = 2,
  692.       .content = VACANT_VERTEX
  693.    },
  694.    //45
  695.    {
  696.       .x = 5,
  697.       .y = 3,
  698.       .z = 3,
  699.       .content = VACANT_VERTEX
  700.    },
  701.    //46
  702.    {
  703.       .x = 4,
  704.       .y = 2,
  705.       .z = 3,
  706.       .content = VACANT_VERTEX
  707.    },
  708.    //47
  709.    {
  710.       .x = 3,
  711.       .y = 2,
  712.       .z = 4,
  713.       .content = VACANT_VERTEX
  714.    },
  715.    //48
  716.    {
  717.       .x = 3,
  718.       .y = 3,
  719.       .z = 5,
  720.       .content = VACANT_VERTEX
  721.    },
  722.    //49
  723.    {
  724.       .x = 4,
  725.       .y = 4,
  726.       .z = 5,
  727.       .content = VACANT_VERTEX
  728.    },
  729.    //50
  730.    {
  731.       .x = 4,
  732.       .y = 5,
  733.       .z = 6,
  734.       .content = VACANT_VERTEX
  735.    },
  736.    //51
  737.    {
  738.       .x = 5,
  739.       .y = 6,
  740.       .z = 6,
  741.       .content = VACANT_VERTEX
  742.    },
  743.    //52
  744.    {
  745.       .x = 6,
  746.       .y = 6,
  747.       .z = 5,
  748.       .content = VACANT_VERTEX
  749.    },
  750.    //53
  751.    {
  752.       .x = 6,
  753.       .y = 5,
  754.       .z = 4,
  755.       .content = VACANT_VERTEX
  756.    },
  757.    //54
  758.    {
  759.       .x = 5,
  760.       .y = 4,
  761.       .z = 4,
  762.       .content = VACANT_VERTEX
  763.    }
  764.    };
  765.    //Copies this set of vertices into game struct
  766.    i = 0;
  767.    while (i < NUM_VERTICES) {
  768.       g->vertices[i] = allVertices[i];
  769.       i++;
  770.    }
  771.    
  772.    //Set all the arcs = 72
  773.    arc allArcs[NUM_ARCS] = {
  774.       //0
  775.       {
  776.          .leftPoint = 29,
  777.          .rightPoint = 0,
  778.          .content = ARC_A
  779.       },
  780.       //1
  781.       {
  782.          .leftPoint = 15,
  783.          .rightPoint = 14,
  784.          .content = ARC_A
  785.       },
  786.       //2
  787.       {
  788.          .leftPoint = 9,
  789.          .rightPoint = 10,
  790.          .content = ARC_B
  791.       },
  792.       //3
  793.       {
  794.          .leftPoint = 25,
  795.          .rightPoint = 24,
  796.          .content = ARC_B
  797.       },
  798.       //4
  799.       {
  800.          .leftPoint = 4,
  801.          .rightPoint = 5,
  802.          .content = ARC_C
  803.       },
  804.       //5
  805.       {
  806.          .leftPoint = 20,
  807.          .rightPoint = 19,
  808.          .content = ARC_C
  809.       },
  810.       //6
  811.       {
  812.          .leftPoint = 0,
  813.          .rightPoint = 1,
  814.       },
  815.       //7
  816.       {
  817.          .leftPoint = 1,
  818.          .rightPoint = 2,
  819.       },
  820.       //8
  821.       {
  822.          .leftPoint = 2,
  823.          .rightPoint = 3,
  824.       },
  825.       //9
  826.       {
  827.          .leftPoint = 3,
  828.          .rightPoint = 4,
  829.       },
  830.       //10
  831.       {
  832.          .leftPoint = 28,
  833.          .rightPoint = 29,
  834.       },
  835.       //11
  836.       {
  837.          .leftPoint = 27,
  838.          .rightPoint = 28,
  839.       },
  840.       //12
  841.       {
  842.          .leftPoint = 26,
  843.          .rightPoint = 27,
  844.       },
  845.       //13
  846.       {
  847.          .leftPoint = 25,
  848.          .rightPoint = 26,
  849.       },  
  850.       //14
  851.       {
  852.          .leftPoint = 24,
  853.          .rightPoint = 45,
  854.       },
  855.       //15
  856.       {
  857.          .leftPoint = 45,
  858.          .rightPoint = 46,
  859.       },
  860.       //16
  861.       {
  862.          .leftPoint = 27,
  863.          .rightPoint = 46,
  864.       },
  865.       //17
  866.       {
  867.          .leftPoint = 46,
  868.          .rightPoint = 47,
  869.       },
  870.       //18
  871.       {
  872.          .leftPoint = 47,
  873.          .rightPoint = 30,
  874.       },
  875.       //19
  876.       {
  877.          .leftPoint = 29,
  878.          .rightPoint = 30,
  879.       },
  880.       //20
  881.       {
  882.          .leftPoint = 30,
  883.          .rightPoint = 31,
  884.       },
  885.       //21
  886.       {
  887.          .leftPoint = 31,
  888.          .rightPoint = 32,
  889.       },
  890.       //22
  891.       {
  892.          .leftPoint = 31,
  893.          .rightPoint = 2,
  894.       },
  895.       //23
  896.       {
  897.          .leftPoint = 32,
  898.          .rightPoint = 33,
  899.       },
  900.       //24
  901.       {
  902.          .leftPoint = 33,
  903.          .rightPoint = 4,
  904.       },
  905.       //25
  906.       {
  907.          .leftPoint = 5,
  908.          .rightPoint = 6,
  909.       },
  910.       //26
  911.       {
  912.          .leftPoint = 7,
  913.          .rightPoint = 6,
  914.       },
  915.       //27
  916.       {
  917.          .leftPoint = 34,
  918.          .rightPoint = 7,
  919.       },
  920.       //28
  921.       {
  922.          .leftPoint = 33,
  923.          .rightPoint = 34,
  924.       },
  925.       //29
  926.       {
  927.          .leftPoint = 35,
  928.          .rightPoint = 34,
  929.       },
  930.       //30
  931.       {
  932.          .leftPoint = 50,
  933.          .rightPoint = 35,
  934.       },
  935.       //31
  936.       {
  937.          .leftPoint = 49,
  938.          .rightPoint = 50,
  939.       },
  940.       //32
  941.       {
  942.          .leftPoint = 49,
  943.          .rightPoint = 32,
  944.       },
  945.       //33
  946.       {
  947.          .leftPoint = 48,
  948.          .rightPoint = 49,
  949.       },
  950.       //34
  951.       {
  952.          .leftPoint = 53,
  953.          .rightPoint = 48,
  954.       },
  955.       //35
  956.       {
  957.          .leftPoint = 47,
  958.          .rightPoint = 48,
  959.       },
  960.       //36
  961.       {
  962.          .leftPoint = 45,
  963.          .rightPoint = 44,
  964.       },
  965.       //37
  966.       {
  967.          .leftPoint = 23,
  968.          .rightPoint = 24,
  969.       },
  970.       //38
  971.       {
  972.          .leftPoint = 23,
  973.          .rightPoint = 22,
  974.       },
  975.       //39
  976.       {
  977.          .leftPoint = 22,
  978.          .rightPoint = 43,
  979.       },
  980.       //40
  981.       {
  982.          .leftPoint = 53,
  983.          .rightPoint = 52,
  984.       },
  985.       //41
  986.       {
  987.          .leftPoint = 52,
  988.          .rightPoint = 51,
  989.       },
  990.       //42
  991.       {
  992.          .leftPoint = 51,
  993.          .rightPoint = 50,
  994.       },
  995.       //43
  996.       {
  997.          .leftPoint = 35,
  998.          .rightPoint = 36,
  999.       },
  1000.       //44
  1001.       {
  1002.          .leftPoint = 36,
  1003.          .rightPoint = 9,
  1004.       },
  1005.       //45
  1006.       {
  1007.          .leftPoint = 9,
  1008.          .rightPoint = 8,
  1009.       },
  1010.       //46
  1011.       {
  1012.          .leftPoint = 7,
  1013.          .rightPoint = 8,
  1014.       },
  1015.       //47
  1016.       {
  1017.          .leftPoint = 16,
  1018.          .rightPoint = 15,
  1019.       },  
  1020.       //48
  1021.       {
  1022.          .leftPoint = 17,
  1023.          .rightPoint = 16,
  1024.       },
  1025.       //49
  1026.       {
  1027.          .leftPoint = 18,
  1028.          .rightPoint = 17,
  1029.       },
  1030.       //50
  1031.       {
  1032.          .leftPoint = 14,
  1033.          .rightPoint = 13,
  1034.       },
  1035.       //51
  1036.       {
  1037.          .leftPoint = 19,
  1038.          .rightPoint = 18,
  1039.       },
  1040.       //52
  1041.       {
  1042.          .leftPoint = 17,
  1043.          .rightPoint = 40,
  1044.       },
  1045.       //53
  1046.       {
  1047.          .leftPoint = 39,
  1048.          .rightPoint = 14,
  1049.       },
  1050.       //54
  1051.       {
  1052.          .leftPoint = 13,
  1053.          .rightPoint = 12,
  1054.       },
  1055.       //55
  1056.       {
  1057.          .leftPoint = 40,
  1058.          .rightPoint = 39,
  1059.       },
  1060.       //56
  1061.       {
  1062.          .leftPoint = 12,
  1063.          .rightPoint = 11,
  1064.       },
  1065.       //57
  1066.       {
  1067.          .leftPoint = 21,
  1068.          .rightPoint = 20,
  1069.       },
  1070.       //58
  1071.       {
  1072.          .leftPoint = 19,
  1073.          .rightPoint = 42,
  1074.       },
  1075.       //59
  1076.       {
  1077.          .leftPoint = 41,
  1078.          .rightPoint = 40,
  1079.       },
  1080.       //60
  1081.       {
  1082.          .leftPoint = 39,
  1083.          .rightPoint = 38,
  1084.       },
  1085.       //61
  1086.       {
  1087.          .leftPoint = 37,
  1088.          .rightPoint = 12,
  1089.       },
  1090.       //62
  1091.       {
  1092.          .leftPoint = 11,
  1093.          .rightPoint = 10,
  1094.       },
  1095.       //63
  1096.       {
  1097.          .leftPoint = 42,
  1098.          .rightPoint = 41,
  1099.       },
  1100.       //64
  1101.       {
  1102.          .leftPoint = 38,
  1103.          .rightPoint = 37,
  1104.       },
  1105.       //65
  1106.       {
  1107.          .leftPoint = 21,
  1108.          .rightPoint = 22,
  1109.       },
  1110.       //66
  1111.       {
  1112.          .leftPoint = 43,
  1113.          .rightPoint = 42,
  1114.       },
  1115.       //67
  1116.       {
  1117.          .leftPoint = 41,
  1118.          .rightPoint = 52,
  1119.       },
  1120.       //68
  1121.       {
  1122.          .leftPoint = 51,
  1123.          .rightPoint = 38,
  1124.       },
  1125.       //69
  1126.       {
  1127.          .leftPoint = 37,
  1128.          .rightPoint = 36,
  1129.       },
  1130.       //70
  1131.       {
  1132.          .leftPoint = 43,
  1133.          .rightPoint = 44,
  1134.       },
  1135.       //71
  1136.       {
  1137.          .leftPoint = 44,
  1138.          .rightPoint = 53,
  1139.       },  
  1140.          
  1141.    };
  1142.    
  1143.    //Copy this set of arcs into game struct
  1144.    i = 0;
  1145.    while (i < NUM_ARCS) {
  1146.       g->arcs[i] = allArcs[i];
  1147.       i++;
  1148.    }
  1149.        
  1150.    //Set up all the retraining centres
  1151.    g->retrainingCentres[0].arc = 25;  
  1152.    g->retrainingCentres[0].retrainingType = 3;
  1153.    
  1154.    g->retrainingCentres[1].arc = 47;
  1155.    g->retrainingCentres[1].retrainingType = 3;
  1156.      
  1157.    g->retrainingCentres[2].arc = 38;
  1158.    g->retrainingCentres[2].retrainingType = 3;
  1159.      
  1160.    g->retrainingCentres[3].arc = 13;
  1161.    g->retrainingCentres[3].retrainingType = 3;
  1162.      
  1163.    g->retrainingCentres[4].arc = 10;
  1164.    g->retrainingCentres[4].retrainingType = 2;
  1165.    g->retrainingCentres[4].discipline = STUDENT_MTV;
  1166.      
  1167.    g->retrainingCentres[5].arc = 8;
  1168.    g->retrainingCentres[5].retrainingType = 2;
  1169.    g->retrainingCentres[5].discipline = STUDENT_MMONEY;
  1170.      
  1171.    g->retrainingCentres[6].arc = 45;
  1172.    g->retrainingCentres[6].retrainingType = 2;
  1173.    g->retrainingCentres[6].discipline = STUDENT_BQN;
  1174.      
  1175.    g->retrainingCentres[7].arc = 51;
  1176.    g->retrainingCentres[7].retrainingType = 2;
  1177.    g->retrainingCentres[7].discipline = STUDENT_BPS;
  1178.      
  1179.    g->retrainingCentres[8].arc = 54;
  1180.    g->retrainingCentres[8].retrainingType = 2;
  1181.    g->retrainingCentres[8].discipline = STUDENT_MJ;  
  1182.      
  1183.    return g;
  1184. }
  1185.    
  1186. void disposeGame (Game g) {
  1187.    assert (g != NULL);
  1188.    free (g);
  1189. }
  1190.    
  1191. void makeAction (Game g, action a) {
  1192.    int uni;
  1193.    int currentPlayer;
  1194.    currentPlayer = getWhoseTurn(g);
  1195.    playerCodes codes = getPlayerCodes(g, currentPlayer);
  1196.    if (a.actionCode == BUILD_CAMPUS) {
  1197.       g->vertices[getVertexID(g, a.destination)].content  
  1198.          = codes.playersCampus;
  1199.       g->students[currentPlayer][STUDENT_BPS]--;
  1200.       g->students[currentPlayer][STUDENT_BQN]--;
  1201.       g->students[currentPlayer][STUDENT_MJ]--;
  1202.       g->students[currentPlayer][STUDENT_MTV]--;
  1203.    } else if (a.actionCode == BUILD_GO8) {
  1204.       g->vertices[getVertexID(g, a.destination)].content  
  1205.          = codes.playersGO8;
  1206.       g->students[currentPlayer][STUDENT_MJ] -= 2;
  1207.       g->students[currentPlayer][STUDENT_MMONEY] -= 3;      
  1208.    } else if (a.actionCode == OBTAIN_ARC) {
  1209.       g->arcs[getARCID(g, a.destination)].content = codes.playersARC;
  1210.       g->students[currentPlayer][STUDENT_BPS]--;
  1211.       g->students[currentPlayer][STUDENT_BQN]--;
  1212.    } else if (a.actionCode == OBTAIN_PUBLICATION) {
  1213.       g->publications[currentPlayer]++;
  1214.       g->students[currentPlayer][STUDENT_MJ]--;
  1215.       g->students[currentPlayer][STUDENT_MTV]--;
  1216.       g->students[currentPlayer][STUDENT_MMONEY]--;
  1217.    } else if (a.actionCode == OBTAIN_IP_PATENT) {
  1218.       g->patents[currentPlayer]++;
  1219.       g->students[currentPlayer][STUDENT_MJ]--;
  1220.       g->students[currentPlayer][STUDENT_MTV]--;
  1221.       g->students[currentPlayer][STUDENT_MMONEY]--;
  1222.    } else if (a.actionCode == RETRAIN_STUDENTS) {
  1223.       int exchange = getExchangeRate(g, currentPlayer, a.disciplineFrom,
  1224.          a.disciplineTo);
  1225.       g->students[currentPlayer][a.disciplineFrom] -= exchange;
  1226.       g->students[currentPlayer][a.disciplineTo] += 1;
  1227.    }
  1228.    g->mostARCs = getMostARCs(g);
  1229.    g->mostPubs = getMostPublications(g);
  1230.      
  1231.    //Recalculate KPI
  1232.    uni = UNI_A;
  1233.    while (uni <= UNI_C) {
  1234.       g->KPI[uni] = 0;
  1235.       g->KPI[uni] += (getCampuses (g, uni)) * 10;
  1236.       g->KPI[uni] += (getGO8s (g, uni)) * 20;
  1237.       g->KPI[uni] += (getARCs (g, uni)) * 2;
  1238.       g->KPI[uni] += (getIPs (g, uni)) * 10;
  1239.        
  1240.       if (getMostARCs(g) == uni) {
  1241.          g->KPI[uni] += 10;
  1242.       }
  1243.       if (getMostPublications(g) == uni) {
  1244.          g->KPI[uni] += 10;
  1245.       }
  1246.       uni++;
  1247.    }
  1248. }
  1249.    
  1250. void throwDice (Game g, int diceScore) {
  1251.    int i, j;
  1252.    int currentUni;
  1253.    int x, y, z;
  1254.    int vx, vy, vz;
  1255.    int student, content;
  1256.        
  1257.    currentUni = g->currentPlayer - 1;
  1258.    currentUni = (currentUni+1) % NUM_UNIS;
  1259.    g->currentPlayer = currentUni + 1;
  1260.    g->currentTurn++;  
  1261.    g->currentDice = diceScore;
  1262.      
  1263.    //Distribute students
  1264.       //Find all regions with that dice score
  1265.          
  1266.       i = 0;
  1267.       while (i < NUM_REGIONS) {
  1268.          if (g->regions[i].diceNumber == diceScore) {
  1269.             x = g->regions[i].x;
  1270.             y = g->regions[i].y;
  1271.             z = g->regions[i].z;
  1272.             student = g->regions[i].discipline;
  1273.             //Each of the vertices on the region with campus/GO8
  1274.             j = 0;
  1275.             while (j < NUM_VERTICES) {
  1276.                vx = g->vertices[j].x;
  1277.                vy = g->vertices[j].y;
  1278.                vz = g->vertices[j].z;
  1279.                content = g->vertices[j].content;
  1280.                if ((((vx-x)*(vx-x) + (vy-y)*(vy-y) + (vz-z)*(vz-z))
  1281.                   == 2) && (content != VACANT_VERTEX)) {
  1282.                   //Distribute to owner
  1283.                   if (content == CAMPUS_A) {
  1284.                      g->students[UNI_A][student] += 1;
  1285.                   } else if (content == CAMPUS_B) {
  1286.                      g->students[UNI_B][student] += 1;
  1287.                   } else if (content == CAMPUS_C) {
  1288.                      g->students[UNI_C][student] += 1;
  1289.                   } else if (content == GO8_A) {
  1290.                      g->students[UNI_A][student] += 2;
  1291.                   } else if (content == GO8_B) {
  1292.                      g->students[UNI_B][student] += 2;
  1293.                   } else if (content == GO8_C) {
  1294.                      g->students[UNI_C][student] += 2;
  1295.                   }
  1296.                }
  1297.               j++;
  1298.             }          
  1299.          }
  1300.          i++;        
  1301.       }
  1302.      
  1303.    //If 7 is rolled, replace with THD
  1304.    if (diceScore == 7) {
  1305.       i = UNI_A;
  1306.       while (i <= UNI_C) {
  1307.          g->students[i][STUDENT_THD] += g->students[i][STUDENT_MTV] +  
  1308.             g->students[i][STUDENT_MMONEY];
  1309.          g->students[i][STUDENT_MTV] = 0;
  1310.          g->students[i][STUDENT_MMONEY] = 0;
  1311.       i++;
  1312.       }
  1313.    }
  1314. }
  1315.    
  1316. //---------'Getters'
  1317.    
  1318. // what type of students are produced by the specified region?
  1319. // see discipline codes above
  1320. int getDiscipline (Game g, int regionID) {
  1321.    return g->regions[regionID].discipline;
  1322. }
  1323.    
  1324. // what dice value produces students in the specified region?
  1325. // 2..12
  1326. int getDiceValue (Game g, int regionID) {
  1327.    return g->regions[regionID].diceNumber;
  1328. }
  1329.    
  1330. int getMostARCs (Game g) {
  1331.    int uni;
  1332.    int i;
  1333.    uni = g->mostARCs;  
  1334.    i = UNI_A;
  1335.    if (getARCs(g, 0) != 66) {
  1336.       uni = UNI_A;
  1337.    }
  1338.    while (i <= UNI_C) {
  1339.       if (getARCs (g, i) > getARCs (g, uni)) {
  1340.          uni = i;
  1341.       }
  1342.    i++;
  1343.    }  
  1344.    return uni;
  1345. }
  1346.    
  1347. int getMostPublications (Game g) {
  1348.    int uni;
  1349.    uni = g->mostPubs;  
  1350.    int i = UNI_A;
  1351.    if (g->mostPubs != NO_ONE){
  1352.       i = UNI_A;
  1353.    }
  1354.    while (i <= UNI_C) {
  1355.       if (getPublications (g, i) > getPublications (g, uni)) {
  1356.          uni = i;
  1357.       }
  1358.    i++;
  1359.    }  
  1360.    return uni;
  1361. }
  1362.    
  1363. int getTurnNumber (Game g) {
  1364.    return g->currentTurn;
  1365. }
  1366.    
  1367. int getWhoseTurn (Game g) {
  1368.    return g->currentPlayer;
  1369. }
  1370.    
  1371. int getCampus (Game g, path pathToVertex) {
  1372.    int vertex = getVertexID (g, pathToVertex);
  1373.    return g->vertices[vertex].content;
  1374. }
  1375.    
  1376. int getARC (Game g, path pathToEdge) {
  1377.    int arc = getARCID (g, pathToEdge);
  1378.    return g->arcs[arc].content;
  1379. }
  1380.    
  1381. //------Legal action
  1382.    
  1383. int isLegalAction (Game g, action a) {
  1384.    int pos;
  1385.    int isLegal = TRUE;
  1386.    int currentPlayer = getWhoseTurn(g);
  1387.    playerCodes codes = getPlayerCodes (g, currentPlayer);
  1388.    
  1389.    //checking for each of the action codes
  1390.    if (a.actionCode == PASS) {
  1391.          
  1392.    } else if (a.actionCode == BUILD_CAMPUS) {
  1393.       int vertexToBuild = getVertexID (g, a.destination);
  1394.       //has enough students
  1395.      
  1396.       if (((getStudents (g, currentPlayer, STUDENT_BPS) >= 1) &&
  1397.            (getStudents (g, currentPlayer, STUDENT_BQN) >= 1) &&
  1398.            (getStudents (g, currentPlayer, STUDENT_MJ) >= 1) &&
  1399.            (getStudents (g, currentPlayer, STUDENT_MTV) >= 1))
  1400.            == FALSE) {
  1401.          isLegal = FALSE;
  1402.       }
  1403.          
  1404.       pos = 0;
  1405.       while (a.destination[pos] != '\0') {
  1406.          pos++;
  1407.       }
  1408.       //valid vertex/path - size & is in array
  1409.       if ((pos >= PATH_LIMIT) || vertexToBuild >= NUM_VERTICES) {  
  1410.       //need to test - edge cases
  1411.          //printf("pos is %d and vertex is %d\n",pos, vertexToBuild);
  1412.         // printf("path is %s", a.destination);
  1413.          printf("edge case failed\n");
  1414.          isLegal = FALSE;
  1415.       }
  1416.          
  1417.       //is vacant
  1418.       if (getCampus(g, a.destination) != VACANT_VERTEX) {
  1419.          isLegal = FALSE;
  1420.          printf("not vacant\n");
  1421.       }
  1422.          
  1423.       //has arc on it and no campus on vertex next to it
  1424.       int i = 0;
  1425.       int ARCsEmpty = TRUE;
  1426.       int ARCsOwned = FALSE;
  1427.          
  1428.       while ((i < NUM_ARCS) && (ARCsEmpty == TRUE)) {
  1429.          int leftPoint = g->arcs[i].leftPoint;
  1430.          int rightPoint = g->arcs[i].rightPoint;
  1431.          int leftContent = g->vertices[leftPoint].content;
  1432.          int rightContent = g->vertices[rightPoint].content;
  1433.          
  1434.          if (leftPoint == vertexToBuild) {
  1435.             if (rightContent != VACANT_VERTEX) {
  1436.                ARCsEmpty = FALSE;
  1437.             }  
  1438.             if (g->arcs[i].content == codes.playersARC) {
  1439.                ARCsOwned = TRUE;
  1440.             }
  1441.          } else if (rightPoint == vertexToBuild) {
  1442.             if (leftContent != VACANT_VERTEX) {
  1443.                ARCsEmpty = FALSE;
  1444.             }  
  1445.             if (g->arcs[i].content == codes.playersARC) {
  1446.                ARCsOwned = TRUE;
  1447.             }
  1448.          }
  1449.          i++;
  1450.       }
  1451.      
  1452.       if ((ARCsEmpty == FALSE) || (ARCsOwned == FALSE)) {
  1453.          isLegal = FALSE;
  1454.       }
  1455.        
  1456.    } else if (a.actionCode == BUILD_GO8) {
  1457.    //has enough students
  1458.       if (((getStudents (g, currentPlayer, STUDENT_MJ) >= 2) &&
  1459.          (getStudents (g, currentPlayer, STUDENT_MMONEY) >= 3))  
  1460.          == FALSE) {
  1461.          isLegal = FALSE;
  1462.       }
  1463.    
  1464.       //has campus there
  1465.       if (getCampus(g, a.destination) != codes.playersCampus) {
  1466.          isLegal = FALSE;
  1467.       }
  1468.      
  1469.       //less than 8 GO8s
  1470.       if (getGO8s (g, currentPlayer) >= 8) {
  1471.          isLegal = FALSE;
  1472.       }
  1473.      
  1474.    } else if (a.actionCode == OBTAIN_ARC) {
  1475.       int arcToBuild = getARCID (g, a.destination);
  1476.      
  1477.       //has enough students
  1478.       if (((getStudents (g, currentPlayer, STUDENT_BPS) >= 1) &&
  1479.         (getStudents (g, currentPlayer, STUDENT_BQN) >= 1)) == FALSE) {
  1480.          printf("not enough students");
  1481.          isLegal = FALSE;
  1482.       }
  1483.      
  1484.       //valid ARC
  1485.       //printf ("This is arc number %d\n", arcToBuild);
  1486.       //counting how long the destination path is
  1487.       pos = 0;
  1488.       while (a.destination[pos] != '\0') {
  1489.          pos++;
  1490.       }
  1491.       //printf ("size of desination is %d\n", pos);
  1492.       //printf ("arcToBuild has value %d\n", arcToBuild);
  1493.       if ((pos >= PATH_LIMIT) || (arcToBuild >= NUM_ARCS)) {  
  1494.       //check edge cases
  1495.          isLegal = FALSE;
  1496.          printf("invalid arc\n");
  1497.       }
  1498.      
  1499.       //is vacant
  1500.       if (getARC(g, a.destination) != VACANT_ARC) {
  1501.          isLegal = FALSE;
  1502.          printf("not vacant arc");
  1503.       }
  1504.      
  1505.       //has arc or campus near it belonging to the player
  1506.       int hasTouching = FALSE;
  1507.       int leftPoint = g->arcs[arcToBuild].leftPoint;
  1508.       int rightPoint = g->arcs[arcToBuild].rightPoint;
  1509.       int leftContent = g->vertices[leftPoint].content;
  1510.       int rightContent = g->vertices[rightPoint].content;
  1511.      
  1512.       if ((leftContent == codes.playersCampus) ||  
  1513.          (rightContent == codes.playersCampus)) {
  1514.          hasTouching = TRUE;
  1515.       }
  1516.      
  1517.       int i = 0;
  1518.          while ((i < NUM_ARCS) && (hasTouching == FALSE)) {
  1519.             if ((g->arcs[i].leftPoint == leftPoint) ||
  1520.                 (g->arcs[i].leftPoint == rightPoint) ||
  1521.                 (g->arcs[i].rightPoint == leftPoint) ||
  1522.                 (g->arcs[i].rightPoint == rightPoint)) {
  1523.                 if (g->arcs[i].content == codes.playersARC) {
  1524.                    hasTouching = TRUE;
  1525.                 }
  1526.             }
  1527.          i++;
  1528.          }
  1529.      
  1530.       if (hasTouching == FALSE) {
  1531.          printf("nothing near this arc belonging to the player");
  1532.          isLegal = FALSE;
  1533.       }
  1534.        
  1535.    } else if (a.actionCode == START_SPINOFF) {
  1536.    //has enough students
  1537.       if (((getStudents (g, currentPlayer, STUDENT_MJ) >= 1) &&
  1538.          (getStudents (g, currentPlayer, STUDENT_MTV) >= 1) &&
  1539.          (getStudents (g, currentPlayer, STUDENT_MMONEY) >= 1))  
  1540.          == FALSE ) {
  1541.          isLegal = FALSE;      
  1542.       }
  1543.        
  1544.    } else if ((a.actionCode == OBTAIN_PUBLICATION) ||
  1545.              (a.actionCode == OBTAIN_IP_PATENT)) {
  1546.       isLegal = FALSE;
  1547.      
  1548.    } else if (a.actionCode == RETRAIN_STUDENTS) {
  1549.       //is not THD
  1550.       if (a.disciplineFrom == STUDENT_THD) {
  1551.          isLegal = FALSE;
  1552.       }
  1553.       //has enough students
  1554.       if (getStudents (g, currentPlayer, a.disciplineFrom) <
  1555.          getExchangeRate  
  1556.          (g, currentPlayer, a.disciplineFrom, a.disciplineTo)) {
  1557.          isLegal = FALSE;          
  1558.       }
  1559.        
  1560.    } else {
  1561.       isLegal = FALSE;
  1562.    }
  1563.    return isLegal;
  1564. }
  1565.    
  1566. //-------Player stats
  1567. int getKPIpoints (Game g, int player) {
  1568.    return g->KPI[player];
  1569. }
  1570.    
  1571. int getARCs (Game g, int player) {
  1572.    playerCodes codes = getPlayerCodes (g, player);
  1573.    int numArcs = 0;
  1574.    int i = 0;
  1575.      
  1576.    while (i < NUM_ARCS) {
  1577.       if (g->arcs[i].content == codes.playersARC) {
  1578.          numArcs++;
  1579.       }
  1580.       i++;
  1581.    }
  1582.      
  1583.    return numArcs;
  1584. }
  1585.    
  1586. int getGO8s (Game g, int player) {
  1587.    playerCodes codes = getPlayerCodes (g, player);
  1588.    int numGO8s = 0;
  1589.    int i = 0;
  1590.      
  1591.    while (i < NUM_VERTICES) {
  1592.       if (g->vertices[i].content == codes.playersGO8) {
  1593.          numGO8s++;
  1594.       }
  1595.       i++;
  1596.    }
  1597.    return numGO8s;
  1598. }
  1599.    
  1600. int getCampuses (Game g, int player) {
  1601.    playerCodes codes = getPlayerCodes (g, player);
  1602.    int numCampuses = 0;
  1603.    int i = 0;
  1604.      
  1605.    while (i < NUM_VERTICES) {
  1606.       if (g->vertices[i].content == codes.playersCampus) {
  1607.          numCampuses++;
  1608.       }
  1609.       i++;
  1610.    }
  1611.      
  1612.    return numCampuses;
  1613. }
  1614.    
  1615. int getIPs (Game g, int player) {
  1616.    return g->patents[player];
  1617. }  
  1618.    
  1619. int getPublications (Game g, int player) {
  1620.    return g->publications[player];
  1621. }
  1622.    
  1623. int getStudents (Game g, int player, int discipline) {
  1624.    assert (player != NO_ONE);
  1625.    return g->students[player][discipline];
  1626. }
  1627.    
  1628. //------Exchange Rate
  1629. int getExchangeRate (Game g, int player,
  1630.                      int disciplineFrom, int disciplineTo) {                
  1631.    playerCodes codes = getPlayerCodes (g, player);
  1632.    int i;
  1633.    int exchangeRate = 4;
  1634.    i = 0;
  1635.    while ((i < NUM_RETRAININGCENTRES) && (exchangeRate > 2)) {
  1636.       int arc = g->retrainingCentres[i].arc;
  1637.       int leftPoint = g->arcs[arc].leftPoint;
  1638.       int rightPoint = g->arcs[arc].rightPoint;
  1639.       int leftContent = g->vertices[leftPoint].content;
  1640.       int rightContent = g->vertices[rightPoint].content;
  1641.       if ((leftContent == codes.playersCampus) ||  
  1642.           (rightContent == codes.playersCampus) ||
  1643.           (leftContent == codes.playersGO8) ||  
  1644.           (rightContent == codes.playersGO8)) {
  1645.           int retrainingType = g->retrainingCentres[i].retrainingType;
  1646.           int discipline = g->retrainingCentres[i].discipline;
  1647.          if ((retrainingType == 2) && (discipline == disciplineFrom)) {
  1648.                exchangeRate = 2;
  1649.          } else if (retrainingType == 3) {
  1650.                exchangeRate = 3;
  1651.          }    
  1652.       }
  1653.    i++;
  1654.    }  
  1655.    return exchangeRate;
  1656. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement