5 * Copyright (C) 2003, 2007 Thomas Perl <thp@perli.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
35 typedef unsigned char bool;
67 bool responsible
; /* responsible for the next fault (if any) */
68 unsigned char desire
; /* what the player aims to do (0=normal, 1=upper edge, 2=lower edge)*/
69 bool type
; /* is this player ai-controlled or human? */
70 float ball_dest
; /* prospective y-position of ball */
71 bool state_locked
; /* enabled when user keeps pressing the "hit" key */
72 int game
; /* score for the current game */
73 int sets
[SETS_TO_WIN
*2]; /* score for each set */
96 char game_score_str
[50];
97 char sets_score_str
[50];
98 unsigned char referee
;
99 unsigned int current_set
;
102 unsigned int court_type
;
103 unsigned int history
[3];
104 unsigned int history_size
;
105 bool history_is_locked
;
106 unsigned char ngram
[NGRAM_STEPS
][NGRAM_STEPS
][NGRAM_STEPS
];
107 float ngram_prediction
;
111 unsigned char joystick_a
;
116 #define GAME_TICKS 15
118 #define GROUND_PHASE 0.4
119 #define PHASE_AMP 3.2
121 #define BALL_JUMP_MIN 4
122 #define BALL_JUMP_MAX 10
123 #define BALL_DEFAULT_SPEED 3.0
125 #define RACKET_X_MID 15
126 #define RACKET_Y_MID 24
131 #define GAME_X_MIN 41.0*2
132 #define GAME_X_MAX 270.0*2
133 #define GAME_X_MID ((GAME_X_MIN+GAME_X_MAX)/2)
135 #define GAME_Y_MIN 155.0
136 #define GAME_Y_MAX 330.0
137 #define GAME_Y_MID ((GAME_Y_MIN+GAME_Y_MAX)/2)
139 #define GAME_EDGE_AREA 20.0
140 #define GAME_EDGE_UPPER GAME_Y_MIN+GAME_EDGE_AREA
141 #define GAME_EDGE_LOWER GAME_Y_MAX-GAME_EDGE_AREA
143 #define PLAYER_Y_MIN 0.0
144 #define PLAYER_Y_MAX 1.0*HEIGHT
146 #define IS_OFFSCREEN_Y(y) (((y)<0-BALL_Y_MID*2) || ((y)>HEIGHT+BALL_Y_MID*2))
147 #define IS_OFFSCREEN_X(x) (((x)<0-BALL_X_MID*2) || ((x)>WIDTH+BALL_X_MID*2))
148 #define IS_OFFSCREEN(x,y) ((IS_OFFSCREEN_X(x)) || (IS_OFFSCREEN_Y(y)))
149 #define IS_OUT_Y(y) (y<GAME_Y_MIN || y>GAME_Y_MAX)
150 #define IS_OUT_X(x) (x<GAME_X_MIN || x>GAME_X_MAX)
152 #define PLAYER_AREA_Y RACKET_Y_MID
153 #define PLAYER_AREA_X RACKET_X_MID
154 #define IS_NEAR_Y(py,by) (fabsf(py-by)<PLAYER_AREA_Y)
155 #define IS_NEAR_Y_AI(py,by) (fabsf(py-by)<PLAYER_AREA_Y/3.5)
156 #define IS_NEAR_X(px,bx) (fabsf(px-bx)<PLAYER_AREA_X)
157 #define IS_NEAR_X_AI(px,bx) (fabsf(px-bx)<PLAYER_AREA_X*2)
159 #define PLAYER_MOVE_Y 6.0
160 #define PLAYER_STATE_MAX 7
161 #define PLAYER_POWERSHOT 6.2
163 #define MOVE_Y_SEED 3
166 void render( GameState
*);
167 bool step( GameState
*);
168 void limit_value( float*, float, float);
169 float get_phase( GameState
*);
170 float get_move_y( GameState
*, unsigned char);
171 void input_human( Player
*, bool, bool, bool, GameState
*);
172 void input_ai( Player
*, Ball
*, Player
*, GameState
*);
173 void game_setup_serve( GameState
*);
174 float ngram_predictor( GameState
*);
176 void score_game( GameState
*, bool);
177 char* format_sets( GameState
*);
178 char* format_game( GameState
*);
179 char* format_status( GameState
*);
180 int game_get_winner( GameState
*);