File: cluster.hc

package info (click to toggle)
craft 3.5-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,000 kB
  • ctags: 1,602
  • sloc: cpp: 3,794; makefile: 2,319; ansic: 857; sh: 385
file content (108 lines) | stat: -rw-r--r-- 1,955 bytes parent folder | download | duplicates (4)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

#include "cluster.h"
#include "craft.h"


cluster::cluster (char name [])
  {init_params;
   load_params;
   num_members = 0;

.  init_params
     {for (int i = 0; i < max_types; i++)
        anz [i] = 0;
     }.

.  load_params
     {FILE *f;
      int  type;

      f_open (f, complete (name, ".cluster"), "r"); 
      while (another_record)
        {read_record;
        };
      fclose (f);
    }.

.  read_record
     {fscanf (f, "%d", &anz [type]); 
     }.

.  another_record
    (fscanf (f, "%d", &type) != EOF).

  }

cluster::~cluster ()
  {
  }

int cluster::match (int own_color)
  {int  m_anz   [max_types];
   int  rest;
   int  size;
   bool grabbed [max_objects];

   init;
   pick_up;
   return (size - rest);

.  init
     {rest        = 0;
      size        = 0;
      num_members = 0;
      for (int i = 0; i < max_types; i++)
        {m_anz [i] =  anz [i];
         rest      += anz [i];
         size      += anz [i];
        };
      for (int i = 0; i < max_objects; i++)
        {grabbed [i] = false;
        };
     }.

.  pick_up
     {bool knight_replace;

      knight_replace = false;
      perform_pickup;
      if (rest > 0)
         {knight_replace = true;
          perform_pickup;
         };
     }.

.  perform_pickup
     {for (int i = 0; i < max_objects; i++)
       {check_object;
       };
     }.

.  check_object
     {if (! grabbed          [i] && 
          ! objects->is_free [i] && 
          objects->color [i] == own_color)
         perhaps_grab_object;
     }.

.  perhaps_grab_object
     {int t = objects->type [i];

      if (m_anz [t] > 0 || is_knight_replace)
         grab_man;
     }.

.  is_knight_replace
     (knight_replace && t == object_pawn && m_anz [object_knight] > 0).

.  grab_man
     {rest--;
      if   (knight_replace)
           m_anz [object_knight]--;
      else m_anz [t]--;
      id      [num_members] = i;
      grabbed [i]           = true;
      num_members++;
     }.
 
  }