Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
APP_Reversi.c
00001 /********************************************************************* 00002 * SEGGER Microcontroller GmbH * 00003 * Solutions for real time microcontroller applications * 00004 ********************************************************************** 00005 * * 00006 * (c) 1996 - 2018 SEGGER Microcontroller GmbH * 00007 * * 00008 * Internet: www.segger.com Support: support@segger.com * 00009 * * 00010 ********************************************************************** 00011 00012 ** emWin V5.48 - Graphical user interface for embedded applications ** 00013 All Intellectual Property rights in the Software belongs to SEGGER. 00014 emWin is protected by international copyright laws. Knowledge of the 00015 source code may not be used to write a similar product. This file may 00016 only be used in accordance with the following terms: 00017 00018 The software has been licensed to Cypress Semiconductor Corporation, 00019 whose registered office is situated at 198 Champion Ct. San Jose, CA 00020 95134 USA solely for the purposes of creating libraries for Cypress 00021 PSoC3 and PSoC5 processor-based devices, sublicensed and distributed 00022 under the terms and conditions of the Cypress End User License 00023 Agreement. 00024 Full source code is available at: www.segger.com 00025 00026 We appreciate your understanding and fairness. 00027 ---------------------------------------------------------------------- 00028 Licensing information 00029 Licensor: SEGGER Microcontroller Systems LLC 00030 Licensed to: Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA 00031 Licensed SEGGER software: emWin 00032 License number: GUI-00319 00033 License model: Services and License Agreement, signed June 10th, 2009 00034 Licensed platform: Any Cypress platform (Initial targets are: PSoC3, PSoC5) 00035 ---------------------------------------------------------------------- 00036 Support and Update Agreement (SUA) 00037 SUA period: 2009-06-12 - 2022-07-27 00038 Contact to extend SUA: sales@segger.com 00039 ---------------------------------------------------------------------- 00040 File : Reversi.c 00041 Purpose : Simple 'reversi' game 00042 00043 With game engine 'SmartGecko' from 00044 Energy Micro AS (http://www.energymicro.com) 00045 Requirements: WindowManager - (x) 00046 MemoryDevices - (x) 00047 AntiAliasing - (x) 00048 VNC-Server - ( ) 00049 PNG-Library - ( ) 00050 TrueTypeFonts - ( ) 00051 ---------------------------------------------------------------------- 00052 */ 00053 00054 #include <string.h> 00055 #include <stdio.h> 00056 00057 #include "GUI.h" 00058 #include "DIALOG.h" 00059 00060 /********************************************************************* 00061 * 00062 * Defines 00063 * 00064 ********************************************************************** 00065 */ 00066 #define USE_SMART_GECKO 0 00067 00068 #define NUM_CELL_X 8 00069 #define NUM_CELL_Y 8 00070 #define AA_USE_HIRES 0 00071 #define AA_FACTOR 1u 00072 #define DESKTOP_COLOR GUI_DARKGREEN 00073 #define CLIENT_COLOR GUI_DARKGRAY 00074 #define GRID_COLOR GUI_BROWN 00075 // 00076 // Menu Ids 00077 // 00078 #define ID_MENU_NEW (GUI_ID_USER + 0) 00079 #define ID_MENU_PASS (GUI_ID_USER + 1) 00080 #define ID_MENU_EXIT (GUI_ID_USER + 2) 00081 #define ID_MENU_SETTINGS (GUI_ID_USER + 3) 00082 #define ID_MENU_ABOUT (GUI_ID_USER + 4) 00083 #define ID_MENU_TEST (GUI_ID_USER + 5) 00084 00085 // 00086 // Defines, Player AI 'SmartGecko' 00087 // 00088 #if (USE_SMART_GECKO) 00089 #define AI_FUNC _PlayerAI_SmartGecko 00090 #define DEPTH 4 00091 #define END_GAME_DEPTH 9 00092 #define INFINITY 1000000 00093 #define WINNING_BONUS 100000 00094 #define VALUE_OF_A_MOVE_POSSIBILITY 15 00095 #define VALUE_OF_AN_UNSAFE_PIECE 8 00096 #define VALUE_OF_A_SAFE_PIECE 20 00097 #define VALUE_OF_A_CORNER 1000 00098 #else 00099 #define AI_FUNC _PlayerAI_FirstValid 00100 #endif 00101 00102 // 00103 // Anti-Aliasing 00104 // 00105 #if AA_USE_HIRES 00106 #define AA_CALCFACTOR AA_FACTOR 00107 #else 00108 #define AA_CALCFACTOR 1u 00109 #endif 00110 00111 // 00112 // Recommended memory to run the sample with adequate performance 00113 // 00114 #define RECOMMENDED_MEMORY (1024L * 10) 00115 00116 /********************************************************************* 00117 * 00118 * Types 00119 * 00120 ********************************************************************** 00121 */ 00122 typedef struct { 00123 U8 aCells[NUM_CELL_X][NUM_CELL_Y]; 00124 U8 aMoves[NUM_CELL_X][NUM_CELL_Y]; 00125 int ActPlayer; 00126 } BOARD; 00127 00128 typedef char REVERSI_AI_Func(const BOARD * pBoard, int * px, int * py); 00129 00130 /********************************************************************* 00131 * 00132 * Static data 00133 * 00134 ********************************************************************** 00135 */ 00136 static REVERSI_AI_Func * _pPlayerAI[2]; 00137 static WM_HWIN _hFrame; 00138 static BOARD _Board; 00139 static int _ShowPossibleMoves = 1; 00140 static int _CellSize; 00141 static int _GameOver; 00142 static int _BoardX0; 00143 static int _BoardY0; 00144 00145 #if (USE_SMART_GECKO) 00146 static BOARD _aBoardStack[END_GAME_DEPTH + 1]; 00147 static int _aaSafe[10][10]; 00148 static int * _px; 00149 static int * _py; 00150 00151 static const int _xs[60] = { 00152 7, 7, 0, 0, 7, 7, 5, 5, 2, 2, 0, 0, 5, 5, 2, 2, 5, 5, 4, 4, 3, 3, 2, 2, 00153 7, 7, 4, 4, 3, 3, 0, 0, 6, 6, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 1, 1, 00154 7, 7, 6, 6, 1, 1, 0, 0, 6, 6, 1, 1 00155 }; 00156 00157 static const int _ys[60] = { 00158 7, 0, 7, 0, 5, 2, 7, 0, 7, 0, 5, 2, 5, 2, 5, 2, 4, 3, 5, 2, 5, 2, 4, 3, 00159 4, 3, 7, 0, 7, 0, 4, 3, 5, 4, 3, 2, 6, 1, 6, 1, 6, 1, 6, 1, 5, 4, 3, 2, 00160 6, 1, 7, 0, 7, 0, 6, 1, 6, 1, 6, 1 00161 }; 00162 00163 static const I32 _aaValues[8][8] = { 00164 { 1000, -100, 25, 0, 0, 25, -100, 1000 }, 00165 { -100, -400, -5, -5, -5, -5, -400, -100 }, 00166 { 25, -5, 12, 2, 2, 12, -5, 25 }, 00167 { 0, -5, 2, 2, 2, 2, -5, 0 }, 00168 { 0, -5, 2, 2, 2, 2, -5, 0 }, 00169 { 25, -5, 12, 2, 2, 12, -5, 25 }, 00170 { -100, -400, -5, -5, -5, -5, -400, -100 }, 00171 { 1000, -100, 25, 0, 0, 25, -100, 1000 } 00172 }; 00173 #endif 00174 00175 /********************************************************************* 00176 * 00177 * Static data, SEGGER logo 00178 * 00179 ********************************************************************** 00180 */ 00181 static GUI_CONST_STORAGE GUI_COLOR _ColorsSeggerLogo[] = { 00182 #if (GUI_USE_ARGB == 1) 00183 0xFFFFFFFF, 0xFFEEEEEE, 0xFF777777, 0xFF555555, 0xFF444444, 0xFF000000, 0xFF333333, 00184 0xFFDDDDDD, 0xFFCCCCCC, 0xFF666666, 0xFF6699FF, 0xFF3333FF, 0xFFCCCCFF, 0xFF3366FF, 00185 0xFF0033FF, 0xFF9999FF, 0xFF99CCFF, 0xFF6666FF, 0xFF0000FF, 0xFF888888, 0xFF222222, 00186 0xFF111111, 0xFF999999, 0xFFAAAAAA, 0xFFBBBBBB 00187 #else 00188 0xFFFFFF, 0xEEEEEE, 0x777777, 0x555555, 0x444444, 0x000000, 0x333333, 00189 0xDDDDDD, 0xCCCCCC, 0x666666, 0xFF9966, 0xFF3333, 0xFFCCCC, 0xFF6633, 00190 0xFF3300, 0xFF9999, 0xFFCC99, 0xFF6666, 0xFF0000, 0x888888, 0x222222, 00191 0x111111, 0x999999, 0xAAAAAA, 0xBBBBBB 00192 #endif 00193 }; 00194 00195 static GUI_CONST_STORAGE GUI_LOGPALETTE _PalSeggerLogo = { 00196 25, // Number of entries 00197 0, // No transparency 00198 &_ColorsSeggerLogo[0] 00199 }; 00200 00201 static GUI_CONST_STORAGE unsigned char _acSeggerLogo[] = { 00202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00205 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 00206 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x00, 0x00, 0x00, 00207 0x00, 0x00, 0x00, 0x02, 0x05, 0x03, 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x09, 0x05, 0x09, 0x00, 0x00, 0x00, 00208 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00209 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00210 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00211 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x0B, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00212 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x10, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00213 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x0A, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00214 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00215 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x00, 0x11, 0x0E, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00216 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0B, 0x0E, 0x0B, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00217 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00218 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00219 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00220 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00221 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0A, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00222 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x11, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00223 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0B, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00224 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0C, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00225 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0C, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00226 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0E, 0x11, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x12, 0x0E, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00227 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x0E, 0x0E, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0A, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00228 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x11, 0x0E, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00229 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00230 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0F, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0B, 0x0E, 0x0B, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00231 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x11, 0x0E, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x13, 0x14, 0x15, 0x05, 0x14, 0x13, 0x00, 0x00, 0x16, 0x04, 0x06, 0x06, 0x06, 0x06, 0x04, 0x01, 0x00, 0x07, 0x09, 0x15, 0x15, 0x05, 0x06, 0x17, 0x00, 0x00, 0x00, 0x07, 0x09, 0x15, 0x15, 0x05, 0x06, 0x16, 0x00, 0x00, 0x07, 0x04, 0x06, 0x06, 0x06, 0x06, 0x06, 0x17, 0x00, 0x13, 0x04, 0x06, 0x06, 0x06, 0x04, 0x13, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00232 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x0E, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x16, 0x05, 0x04, 0x17, 0x16, 0x14, 0x05, 0x17, 0x00, 0x04, 0x05, 0x04, 0x09, 0x09, 0x09, 0x02, 0x01, 0x01, 0x06, 0x05, 0x09, 0x17, 0x02, 0x05, 0x05, 0x17, 0x00, 0x01, 0x06, 0x05, 0x09, 0x17, 0x02, 0x05, 0x05, 0x16, 0x00, 0x17, 0x05, 0x14, 0x09, 0x09, 0x09, 0x09, 0x18, 0x00, 0x06, 0x05, 0x03, 0x09, 0x03, 0x14, 0x05, 0x13, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00233 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x01, 0x00, 0x00, 0x00, 0x09, 0x05, 0x13, 0x00, 0x00, 0x01, 0x16, 0x07, 0x00, 0x03, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x05, 0x02, 0x00, 0x00, 0x00, 0x17, 0x03, 0x08, 0x00, 0x16, 0x05, 0x09, 0x00, 0x00, 0x00, 0x18, 0x03, 0x18, 0x00, 0x17, 0x05, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x05, 0x00, 0x00, 0x00, 0x18, 0x05, 0x03, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00234 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x18, 0x15, 0x05, 0x15, 0x04, 0x13, 0x07, 0x00, 0x00, 0x03, 0x05, 0x14, 0x06, 0x06, 0x06, 0x13, 0x00, 0x04, 0x05, 0x08, 0x00, 0x00, 0x07, 0x07, 0x07, 0x01, 0x00, 0x03, 0x05, 0x08, 0x00, 0x00, 0x07, 0x07, 0x07, 0x01, 0x00, 0x17, 0x05, 0x15, 0x06, 0x06, 0x06, 0x04, 0x07, 0x00, 0x06, 0x05, 0x16, 0x17, 0x17, 0x03, 0x15, 0x16, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00235 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x0D, 0x0E, 0x0E, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0E, 0x0E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x13, 0x04, 0x15, 0x05, 0x15, 0x16, 0x00, 0x03, 0x05, 0x04, 0x09, 0x09, 0x09, 0x16, 0x00, 0x04, 0x05, 0x07, 0x00, 0x08, 0x15, 0x15, 0x15, 0x04, 0x00, 0x03, 0x05, 0x08, 0x00, 0x07, 0x15, 0x05, 0x15, 0x06, 0x00, 0x17, 0x05, 0x14, 0x09, 0x09, 0x09, 0x09, 0x01, 0x00, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x06, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00236 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x11, 0x0E, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0E, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x17, 0x00, 0x00, 0x01, 0x16, 0x05, 0x14, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x05, 0x16, 0x00, 0x00, 0x18, 0x13, 0x05, 0x14, 0x00, 0x02, 0x05, 0x16, 0x00, 0x00, 0x18, 0x16, 0x05, 0x14, 0x00, 0x17, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x05, 0x08, 0x07, 0x08, 0x04, 0x05, 0x17, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00237 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0D, 0x0E, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x03, 0x07, 0x01, 0x17, 0x05, 0x04, 0x00, 0x03, 0x05, 0x16, 0x18, 0x18, 0x18, 0x08, 0x01, 0x08, 0x15, 0x15, 0x17, 0x01, 0x07, 0x03, 0x05, 0x14, 0x00, 0x07, 0x15, 0x15, 0x17, 0x01, 0x07, 0x09, 0x05, 0x14, 0x00, 0x17, 0x05, 0x04, 0x18, 0x18, 0x18, 0x18, 0x07, 0x00, 0x06, 0x05, 0x01, 0x00, 0x00, 0x16, 0x05, 0x02, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00238 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x0B, 0x12, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0E, 0x0E, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x03, 0x05, 0x05, 0x05, 0x05, 0x06, 0x08, 0x00, 0x09, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x17, 0x00, 0x18, 0x14, 0x05, 0x05, 0x05, 0x06, 0x04, 0x14, 0x00, 0x00, 0x18, 0x14, 0x05, 0x05, 0x05, 0x06, 0x04, 0x15, 0x00, 0x08, 0x15, 0x05, 0x05, 0x05, 0x05, 0x05, 0x03, 0x00, 0x06, 0x15, 0x01, 0x00, 0x00, 0x18, 0x05, 0x09, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00239 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x0F, 0x11, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x11, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x16, 0x16, 0x17, 0x01, 0x00, 0x00, 0x01, 0x08, 0x18, 0x18, 0x18, 0x18, 0x08, 0x01, 0x00, 0x00, 0x01, 0x17, 0x16, 0x17, 0x00, 0x07, 0x18, 0x00, 0x00, 0x00, 0x01, 0x17, 0x16, 0x17, 0x01, 0x07, 0x17, 0x00, 0x00, 0x08, 0x18, 0x18, 0x18, 0x18, 0x18, 0x07, 0x00, 0x08, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00240 0x00, 0x00, 0x00, 0x03, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00241 0x00, 0x00, 0x00, 0x03, 0x05, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 00242 0x00, 0x00, 0x00, 0x16, 0x05, 0x04, 0x17, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x03, 0x05, 0x13, 0x00, 0x00, 0x00, 00243 0x00, 0x00, 0x00, 0x00, 0x03, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x01, 0x00, 0x00, 0x00, 00244 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x02, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x02, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 00245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 00248 }; 00249 00250 static GUI_CONST_STORAGE GUI_BITMAP _Logo = { 00251 90, // XSize 00252 46, // YSize 00253 90, // BytesPerLine 00254 8, // BitsPerPixel 00255 _acSeggerLogo, // Pointer to picture data (indices) 00256 &_PalSeggerLogo // Pointer to palette 00257 }; 00258 00259 /********************************************************************* 00260 * 00261 * Function declarations 00262 * 00263 ********************************************************************** 00264 */ 00265 static void _StartNewGame(void); 00266 00267 /********************************************************************* 00268 * 00269 * Static code, helper functions 00270 * 00271 ********************************************************************** 00272 */ 00273 /********************************************************************* 00274 * 00275 * _AddMenuItem 00276 */ 00277 static void _AddMenuItem(MENU_Handle hMenu, MENU_Handle hSubmenu, const char * pText, U16 Id, U16 Flags) { 00278 MENU_ITEM_DATA Item; 00279 00280 Item.pText = pText; 00281 Item.hSubmenu = hSubmenu; 00282 Item.Flags = Flags; 00283 Item.Id = Id; 00284 MENU_AddItem(hMenu, &Item); 00285 } 00286 00287 /********************************************************************* 00288 * 00289 * _CreateMenu 00290 */ 00291 static void _CreateMenu(WM_HWIN hWin) { 00292 MENU_Handle hMenuOptions; 00293 MENU_Handle hMenuGame; 00294 MENU_Handle hMenuHelp; 00295 MENU_Handle hMenu; 00296 00297 MENU_SetDefaultFont(&GUI_Font10_1); 00298 // 00299 // Create menu 'Game' 00300 // 00301 hMenuGame = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00302 _AddMenuItem(hMenuGame, 0, "New game", ID_MENU_NEW, 0); 00303 _AddMenuItem(hMenuGame, 0, "Pass", ID_MENU_PASS, 0); 00304 _AddMenuItem(hMenuGame, 0, NULL, 0, MENU_IF_SEPARATOR); 00305 _AddMenuItem(hMenuGame, 0, "Exit", ID_MENU_EXIT, 0); 00306 // 00307 // Create menu 'Options' 00308 // 00309 hMenuOptions = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00310 _AddMenuItem(hMenuOptions, 0, "Game settings...", ID_MENU_SETTINGS, 0); 00311 // 00312 // Create menu 'Help' 00313 // 00314 hMenuHelp = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00315 _AddMenuItem(hMenuHelp, 0, "About Reversi...", ID_MENU_ABOUT, 0); 00316 // 00317 // Create main menu 00318 // 00319 hMenu = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_HORIZONTAL, 0); 00320 _AddMenuItem(hMenu, hMenuGame, "Game", 0, 0); 00321 _AddMenuItem(hMenu, hMenuOptions, "Options", 0, 0); 00322 _AddMenuItem(hMenu, hMenuHelp, "Help", 0, 0); 00323 // 00324 // Attach menu to framewin 00325 // 00326 FRAMEWIN_AddMenu(hWin, hMenu); 00327 } 00328 00329 /********************************************************************* 00330 * 00331 * _CalcBoardDimensions 00332 */ 00333 static void _CalcBoardDimensions(void) { 00334 GUI_RECT Rect; 00335 00336 WM_GetClientRectEx(WM_GetClientWindow(_hFrame), &Rect); 00337 _CellSize = ((Rect.x1 > Rect.y1) ? Rect.y1 : Rect.x1) / 8; 00338 _BoardX0 = (Rect.x1 - (_CellSize * 8)) / 2; 00339 _BoardY0 = (Rect.y1 - (_CellSize * 8)) / 2; 00340 } 00341 00342 /********************************************************************* 00343 * 00344 * _InvalidateBoard 00345 */ 00346 static void _InvalidateBoard(void) { 00347 WM_InvalidateWindow(WM_GetClientWindow(_hFrame)); 00348 } 00349 00350 /********************************************************************* 00351 * 00352 * _InvalidateCell 00353 */ 00354 static void _InvalidateCell(int x, int y) { 00355 GUI_RECT Rect; 00356 00357 Rect.x0 = _BoardX0 + (x * _CellSize); 00358 Rect.y0 = _BoardY0 + (y * _CellSize); 00359 Rect.x1 = Rect.x0 + _CellSize - 1; 00360 Rect.y1 = Rect.y0 + _CellSize - 1; 00361 WM_InvalidateRect(WM_GetClientWindow(_hFrame), &Rect); 00362 } 00363 00364 /********************************************************************* 00365 * 00366 * _SetCapture 00367 */ 00368 static void _SetCapture(void) { 00369 #if (GUI_SUPPORT_MOUSE & GUI_SUPPORT_CURSOR) 00370 WM_HWIN hWin; 00371 00372 hWin = WM_GetClientWindow(_hFrame); 00373 if (WM_HasCaptured(hWin) == 0) { 00374 WM_SetCapture(hWin, 0); 00375 GUI_CURSOR_Select(&GUI_CursorCrossS); 00376 } 00377 #endif 00378 } 00379 00380 /********************************************************************* 00381 * 00382 * _ReleaseCapture 00383 */ 00384 static void _ReleaseCapture(void) { 00385 #if (GUI_SUPPORT_MOUSE & GUI_SUPPORT_CURSOR) 00386 WM_HWIN hWin; 00387 00388 hWin = WM_GetClientWindow(_hFrame); 00389 if (WM_HasCaptured(hWin)) { 00390 WM_ReleaseCapture(); 00391 GUI_CURSOR_Select(&GUI_CursorArrowM); 00392 } 00393 #endif 00394 } 00395 00396 /********************************************************************* 00397 * 00398 * Static code, game API routines 00399 * 00400 ********************************************************************** 00401 */ 00402 /********************************************************************* 00403 * 00404 * _GetStone 00405 */ 00406 static char _GetStone(const BOARD * pBoard, int x, int y) { 00407 char r; 00408 00409 r = 0; 00410 if ((x >= 0) && (y >= 0) && (x < NUM_CELL_X) && (y < NUM_CELL_Y)) { 00411 r = pBoard->aCells[x][y]; 00412 } 00413 return r; 00414 } 00415 00416 /********************************************************************* 00417 * 00418 * _SetStone 00419 */ 00420 static void _SetStone(BOARD * pBoard, int x, int y) { 00421 if ((x >= 0) && (y >= 0) && (x < NUM_CELL_X) && (y < NUM_CELL_Y)) { 00422 pBoard->aCells[x][y] = pBoard->ActPlayer; 00423 _InvalidateCell(x, y); 00424 } 00425 } 00426 00427 /********************************************************************* 00428 * 00429 * _IsValidMove 00430 */ 00431 static char _IsValidMove(BOARD * pBoard, int x, int y) { 00432 char r; 00433 00434 r = 0; 00435 if ((x >= 0) && (y >= 0) && (x < NUM_CELL_X) && (y < NUM_CELL_Y)) { 00436 r = ((pBoard->aMoves[x][y]) ? 1 : 0); 00437 } 00438 return r; 00439 } 00440 00441 /********************************************************************* 00442 * 00443 * _CheckDirection 00444 */ 00445 static unsigned char _CheckDirection(const BOARD * pBoard, int x, int y, int dx, int dy) { 00446 char Cell; 00447 00448 x += dx; 00449 y += dy; 00450 Cell = _GetStone(pBoard, x, y); 00451 if ((Cell != pBoard->ActPlayer) && (Cell != 0)) { 00452 do { 00453 x += dx; 00454 y += dy; 00455 Cell = _GetStone(pBoard, x, y); 00456 } while ((Cell != pBoard->ActPlayer) && (Cell != 0)); 00457 return ((Cell == pBoard->ActPlayer) ? 1 : 0); 00458 } 00459 return 0; 00460 } 00461 00462 /********************************************************************* 00463 * 00464 * _CalcValidMoves 00465 */ 00466 static int _CalcValidMoves(BOARD * pBoard) { 00467 int r; 00468 int x; 00469 int y; 00470 U8 Valid; 00471 00472 r = 0; 00473 for (y = 0; y < NUM_CELL_Y; y++) { 00474 for (x = 0; x < NUM_CELL_X; x++) { 00475 Valid = 0; 00476 if (pBoard->aCells[x][y] == 0) { 00477 Valid |= _CheckDirection(pBoard, x, y, -1, -1) << 0; 00478 Valid |= _CheckDirection(pBoard, x, y, 0, -1) << 1; 00479 Valid |= _CheckDirection(pBoard, x, y, 1, -1) << 2; 00480 Valid |= _CheckDirection(pBoard, x, y, 1, 0) << 3; 00481 Valid |= _CheckDirection(pBoard, x, y, 1, 1) << 4; 00482 Valid |= _CheckDirection(pBoard, x, y, 0, 1) << 5; 00483 Valid |= _CheckDirection(pBoard, x, y, -1, 1) << 6; 00484 Valid |= _CheckDirection(pBoard, x, y, -1, 0) << 7; 00485 if (Valid) { 00486 r++; 00487 } 00488 } 00489 if (Valid != pBoard->aMoves[x][y]) { 00490 pBoard->aMoves[x][y] = Valid; 00491 _InvalidateCell(x, y); 00492 } 00493 } 00494 } 00495 return r; 00496 } 00497 00498 /********************************************************************* 00499 * 00500 * _DoDirection 00501 */ 00502 static void _DoDirection(BOARD * pBoard, int x, int y, int dx, int dy) { 00503 do { 00504 _SetStone(pBoard, x, y); 00505 x += dx; 00506 y += dy; 00507 } while (_GetStone(pBoard, x, y) != pBoard->ActPlayer); 00508 } 00509 00510 /********************************************************************* 00511 * 00512 * _MakeMove 00513 */ 00514 static void _MakeMove(BOARD * pBoard, int x, int y) { 00515 U8 Valid; 00516 00517 _SetStone(pBoard, x, y); 00518 Valid = pBoard->aMoves[x][y]; 00519 if (Valid & (U8)(1 << 0)) { _DoDirection(pBoard, x, y, -1, -1); } 00520 if (Valid & (U8)(1 << 1)) { _DoDirection(pBoard, x, y, 0, -1); } 00521 if (Valid & (U8)(1 << 2)) { _DoDirection(pBoard, x, y, 1, -1); } 00522 if (Valid & (U8)(1 << 3)) { _DoDirection(pBoard, x, y, 1, 0); } 00523 if (Valid & (U8)(1 << 4)) { _DoDirection(pBoard, x, y, 1, 1); } 00524 if (Valid & (U8)(1 << 5)) { _DoDirection(pBoard, x, y, 0, 1); } 00525 if (Valid & (U8)(1 << 6)) { _DoDirection(pBoard, x, y, -1, 1); } 00526 if (Valid & (U8)(1 << 7)) { _DoDirection(pBoard, x, y, -1, 0); } 00527 } 00528 00529 /********************************************************************* 00530 * 00531 * _CalcScore 00532 */ 00533 static int _CalcScore(const BOARD * pBoard) { 00534 char Cell; 00535 int r; 00536 int x; 00537 int y; 00538 00539 r = 0; 00540 for (y = 0; y < NUM_CELL_Y; y++) { 00541 for (x = 0; x < NUM_CELL_X; x++) { 00542 Cell = pBoard->aCells[x][y]; 00543 if (Cell) { 00544 r += (Cell == pBoard->ActPlayer) ? (1) : (-1); 00545 } 00546 } 00547 } 00548 return r; 00549 } 00550 00551 /********************************************************************* 00552 * 00553 * Static code, Player AI 'SmartGecko' 00554 * 00555 ********************************************************************** 00556 */ 00557 /********************************************************************* 00558 * 00559 * _ValuePieces 00560 * 00561 * Function description 00562 * Find the Value of all the pieces belonging to the given Player. 00563 * A positive Value is good for this Player. 00564 * The Value can also be negative, if the Player occupies tiles 00565 * next to a free corner, which makes it easier for the opponent 00566 * to get to this corner. 00567 */ 00568 #if (USE_SMART_GECKO) 00569 static I32 _ValuePieces(BOARD * pBoard, int Player) { 00570 I32 Sum; 00571 int NumberOfSafe; 00572 int Corners; 00573 int Changed; 00574 int xCorner; 00575 int yCorner; 00576 int s; 00577 int x; 00578 int y; 00579 00580 Sum = 0; 00581 for (y = 1; y <= 8; y++) { 00582 for (x = 1; x <= 8; x++) { 00583 _aaSafe[x][y] = 0; 00584 } 00585 } 00586 Corners = 0; 00587 Corners += (pBoard->aCells[0][0] == Player) ? 1 : 0; 00588 Corners += (pBoard->aCells[7][0] == Player) ? 1 : 0; 00589 Corners += (pBoard->aCells[0][7] == Player) ? 1 : 0; 00590 Corners += (pBoard->aCells[7][7] == Player) ? 1 : 0; 00591 if (Corners) { 00592 // 00593 // Corners are the most valuable asset of the position. 00594 // 00595 Sum += Corners * VALUE_OF_A_CORNER; 00596 // 00597 // Calculate how many pieces are safe, meaning they can never be 00598 // taken back by the opponent. 00599 // 00600 Changed = 0; 00601 while (Changed == 0) { 00602 // 00603 // Repeatedly swipe the board looking for safe pieces, 00604 // until no more safe pieces are found. 00605 // 00606 Changed = 0; 00607 NumberOfSafe = 0; 00608 for (y = 1; y <= 8; y++) { 00609 for (x = 1; x <= 8; x++) { 00610 if (!_aaSafe[x][y] && pBoard->aCells[x - 1][y - 1] == Player) { 00611 // 00612 // A piece can never be taken back if in each of the four directions, 00613 // one of the two neighboring tiles are safe. 00614 // 00615 s = (_aaSafe[x - 1][y ] || _aaSafe[x + 1][y ]) // West - East 00616 && (_aaSafe[x ][y - 1] || _aaSafe[x ][y + 1]) // North - South 00617 && (_aaSafe[x - 1][y - 1] || _aaSafe[x + 1][y + 1]) // NW - SE 00618 && (_aaSafe[x - 1][y + 1] || _aaSafe[x + 1][y - 1]); // SW - NE 00619 if (s) { 00620 _aaSafe[x][y] = 1; 00621 Changed = 1; 00622 ++NumberOfSafe; 00623 } 00624 } 00625 } 00626 Sum += NumberOfSafe * VALUE_OF_A_SAFE_PIECE; 00627 } 00628 } 00629 } 00630 // 00631 // Now add the Value of the unsafe pieces. 00632 // 00633 for (y = 0; y < 8; y++) { 00634 yCorner = (y < 4) ? 0 : 7; 00635 for (x = 0; x < 8; x++) { 00636 if (pBoard->aCells[x][y] == Player && !_aaSafe[x + 1][y + 1]) { 00637 xCorner = x<4 ? 0 : 7; 00638 if (pBoard->aCells[xCorner][yCorner]) { 00639 // 00640 // If the corner is taken, we Value each position in the quadrant the same. 00641 // 00642 Sum += VALUE_OF_AN_UNSAFE_PIECE; 00643 } else { 00644 // 00645 // If the corner is still free, we use a lookup table to find the Value of each position. 00646 // 00647 Sum += _aaValues[x][y]; 00648 } 00649 } 00650 } 00651 } 00652 return Sum; 00653 } 00654 #endif 00655 00656 /********************************************************************* 00657 * 00658 * _Eval 00659 * 00660 * Function description 00661 * Evaluation function for a Reversi board. 00662 * Positive Value means Player 1 is in the lead, 00663 * negative Value means Player 2 is in the lead. 00664 */ 00665 #if (USE_SMART_GECKO) 00666 static I32 _Eval(BOARD * pBoard) { 00667 int ActPlayer; 00668 int MovesA; 00669 int MovesB; 00670 I32 Score; 00671 I32 Value; 00672 00673 ActPlayer = pBoard->ActPlayer; 00674 pBoard->ActPlayer = 1; 00675 MovesA = _CalcValidMoves(pBoard); 00676 pBoard->ActPlayer = 2; 00677 MovesB = _CalcValidMoves(pBoard); 00678 pBoard->ActPlayer = ActPlayer; 00679 if (MovesA == 0 && MovesB == 0) { 00680 // 00681 // The game is over 00682 // 00683 pBoard->ActPlayer = 1; 00684 Score = _CalcScore(pBoard); 00685 pBoard->ActPlayer = ActPlayer; 00686 if (Score==0) { 00687 return 0; 00688 } 00689 if (Score > 0) { 00690 return Score + WINNING_BONUS; 00691 } 00692 if (Score > 0) { 00693 return Score - WINNING_BONUS; 00694 } 00695 } 00696 // 00697 // A high number of possible Moves is very valuable 00698 // 00699 Value = VALUE_OF_A_MOVE_POSSIBILITY * (MovesA - MovesB); 00700 Value += _ValuePieces(pBoard, 1); 00701 Value -= _ValuePieces(pBoard, 2); 00702 return Value; 00703 } 00704 #endif 00705 00706 /********************************************************************* 00707 * 00708 * _Descend 00709 * 00710 * Function description 00711 * Minimax search for the best possible move with Alpha-Beta pruning 00712 */ 00713 #if (USE_SMART_GECKO) 00714 static I32 _Descend(int Depth, I32 Alpha, I32 Beta, int FirstMove) { 00715 BOARD * pBoard; 00716 BOARD * NextBoard; 00717 int Maximize; 00718 int Moves; 00719 int Alt; 00720 int i; 00721 int x; 00722 int y; 00723 00724 pBoard = _aBoardStack + Depth; 00725 NextBoard = _aBoardStack + Depth - 1; 00726 if (Depth == 0) { 00727 return _Eval(pBoard); 00728 } 00729 Moves = _CalcValidMoves(pBoard); 00730 if (Moves == 0) { 00731 // 00732 // The Player has to pass 00733 // 00734 pBoard->ActPlayer = 3 - pBoard->ActPlayer; 00735 Moves = _CalcValidMoves(pBoard); 00736 if (Moves == 0) { 00737 // 00738 // The game is over 00739 // 00740 return _Eval(pBoard); 00741 } 00742 } 00743 Maximize = pBoard->ActPlayer == 1; 00744 for (i = 0; i < 60; ++i) { 00745 // 00746 // Try the possible Moves in order from most attractive to least attractive 00747 // position, to Maximize the effect of the Alpha-Beta pruning. 00748 // 00749 x = _xs[i]; 00750 y = _ys[i]; 00751 if (pBoard->aMoves[x][y]) { 00752 *NextBoard = *pBoard; 00753 _MakeMove(NextBoard, x, y); 00754 NextBoard->ActPlayer = 3 - pBoard->ActPlayer; 00755 // 00756 // Recursively evaluate the board resulting from this move. 00757 // 00758 Alt = _Descend(Depth - 1, Alpha, Beta, 0); 00759 if (Maximize) { 00760 if (Alt > Alpha) { 00761 Alpha = Alt; 00762 if (FirstMove) { 00763 *_px = x; 00764 *_py = y; 00765 } 00766 } 00767 } else { 00768 if (Alt < Beta) { 00769 Beta = Alt; 00770 if (FirstMove) { 00771 *_px = x; 00772 *_py = y; 00773 } 00774 } 00775 } 00776 if (Beta <= Alpha) { 00777 break; 00778 } 00779 } 00780 } 00781 return Maximize ? Alpha : Beta; 00782 } 00783 #endif 00784 00785 /********************************************************************* 00786 * 00787 * _PlayerAI_SmartGecko 00788 */ 00789 #if (USE_SMART_GECKO) 00790 static char _PlayerAI_SmartGecko(const BOARD * pBoard, int * px, int * py) { 00791 int FreeTiles; 00792 int Depth; 00793 int x; 00794 int y; 00795 00796 // 00797 // Initialize the safe board to true to get the edges right 00798 // 00799 for (y = 0; y < 10; y++) { 00800 for (x = 0; x < 10; x++) { 00801 _aaSafe[x][y] = 1; 00802 } 00803 } 00804 *px = -1; 00805 *py = -1; 00806 _px = px; 00807 _py = py; 00808 FreeTiles = 0; 00809 for (y = 0; y < 8; y++) { 00810 for (x = 0; x < 8; x++) { 00811 if (!pBoard->aCells[x][y]) { 00812 ++FreeTiles; 00813 } 00814 } 00815 } 00816 Depth = DEPTH; 00817 if (FreeTiles <= END_GAME_DEPTH) { 00818 // 00819 // In the end game, we expand the search Depth. 00820 // 00821 Depth = FreeTiles; 00822 } 00823 _aBoardStack[Depth] = *pBoard; 00824 _Descend(Depth, -INFINITY, INFINITY, 1); 00825 if (*px == -1) { 00826 return 0; 00827 } 00828 return 1; 00829 } 00830 #endif 00831 00832 /********************************************************************* 00833 * 00834 * Static code, Player AI 'First Valid' 00835 * 00836 ********************************************************************** 00837 */ 00838 /********************************************************************* 00839 * 00840 * _PlayerAI_FirstValid 00841 */ 00842 #if (USE_SMART_GECKO == 0) 00843 static char _PlayerAI_FirstValid(const BOARD * pBoard, int * px, int * py) { 00844 int x; 00845 int y; 00846 00847 for (y = 0; y < NUM_CELL_Y; y++) { 00848 for (x = 0; x < NUM_CELL_X; x++) { 00849 if (pBoard->aMoves[x][y]) { 00850 *px = x; 00851 *py = y; 00852 return 1; 00853 } 00854 } 00855 } 00856 return 0; 00857 } 00858 #endif 00859 00860 /********************************************************************* 00861 * 00862 * Static code, about box 00863 * 00864 ********************************************************************** 00865 */ 00866 /********************************************************************* 00867 * 00868 * _cbAboutBox 00869 */ 00870 static void _cbAboutBox(WM_MESSAGE * pMsg) { 00871 WM_HWIN hWin; 00872 char acText[16] = "V"; 00873 00874 hWin = pMsg->hWin; 00875 switch (pMsg->MsgId) { 00876 case WM_PAINT: 00877 strcat(acText, GUI_GetVersionString()); 00878 GUI_SetColor(GUI_BLACK); 00879 GUI_SetFont(&GUI_Font10_1); 00880 GUI_SetTextMode(GUI_TM_TRANS); 00881 GUI_DrawBitmap(&_Logo, 4, 4); 00882 GUI_DispStringHCenterAt("Reversi V1.0", 49, 48); 00883 GUI_DispStringHCenterAt("emWin", 138, 38); 00884 GUI_DispStringHCenterAt(acText, 138, 48); 00885 GUI_DispStringHCenterAt("Compiled " __DATE__ " "__TIME__, 88, 68); 00886 GUI_DispStringHCenterAt("(c) 1998-2004 Segger", 88, 87); 00887 GUI_DispStringHCenterAt("Microcontroller Systeme GmbH", 88, 97); 00888 GUI_DispStringHCenterAt("www.segger.com", 88, 107); 00889 GUI_DispStringHCenterAt("Programmed by Tobias Quecke", 88, 126); 00890 break; 00891 case WM_NOTIFY_PARENT: 00892 if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) { 00893 GUI_EndDialog(hWin, 1); 00894 } 00895 break; 00896 default: 00897 WM_DefaultProc(pMsg); 00898 } 00899 } 00900 00901 /********************************************************************* 00902 * 00903 * _ShowAboutBox 00904 */ 00905 static void _ShowAboutBox(void) { 00906 WM_HWIN hFrame; 00907 WM_HWIN hItem; 00908 00909 // 00910 // Create framewin 00911 // 00912 hFrame = FRAMEWIN_CreateEx(70, 40, 180, 160, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "About Reversi", _cbAboutBox); 00913 FRAMEWIN_SetClientColor (hFrame, GUI_WHITE); 00914 FRAMEWIN_SetFont (hFrame, &GUI_Font10_1); 00915 FRAMEWIN_SetTextAlign (hFrame, GUI_TA_HCENTER); 00916 // 00917 // Create dialog items 00918 // 00919 hItem = BUTTON_CreateEx(111, 7, 55, 18, WM_GetClientWindow(hFrame), WM_CF_SHOW, 0, GUI_ID_OK); 00920 BUTTON_SetText (hItem, "Ok"); 00921 // 00922 // Exec modal dialog 00923 // 00924 WM_SetFocus(hFrame); 00925 WM_MakeModal(hFrame); 00926 GUI_ExecCreatedDialog(hFrame); 00927 WM_SetFocus(_hFrame); 00928 } 00929 00930 /********************************************************************* 00931 * 00932 * Static code, message box 00933 * 00934 ********************************************************************** 00935 */ 00936 /********************************************************************* 00937 * 00938 * _cbMessageBox 00939 */ 00940 static void _cbMessageBox(WM_MESSAGE * pMsg) { 00941 WM_HWIN hWin; 00942 int Id; 00943 00944 hWin = pMsg->hWin; 00945 switch (pMsg->MsgId) { 00946 case WM_NOTIFY_PARENT: 00947 if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) { 00948 Id = WM_GetId(pMsg->hWinSrc); 00949 GUI_EndDialog(hWin, (Id == GUI_ID_OK) ? 1 : 0); 00950 } 00951 break; 00952 default: 00953 WM_DefaultProc(pMsg); 00954 } 00955 } 00956 00957 /********************************************************************* 00958 * 00959 * _ShowMessageBox 00960 */ 00961 static int _ShowMessageBox(const char * pTitle, const char * pText, int YesNo) { 00962 WM_HWIN hClient; 00963 WM_HWIN hFrame; 00964 WM_HWIN hBut; 00965 int r; 00966 00967 // 00968 // Create framewin 00969 // 00970 hFrame = FRAMEWIN_CreateEx(65, 75, 190, 90, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, pTitle, _cbMessageBox); 00971 FRAMEWIN_SetClientColor (hFrame, GUI_WHITE); 00972 FRAMEWIN_SetFont (hFrame, &GUI_Font10_1); 00973 FRAMEWIN_SetTextAlign (hFrame, GUI_TA_HCENTER); 00974 // 00975 // Create dialog items 00976 // 00977 hClient = WM_GetClientWindow(hFrame); 00978 TEXT_CreateEx(10, 7, 170, 30, hClient, WM_CF_SHOW, GUI_TA_HCENTER, 0, pText); 00979 if (YesNo) { 00980 hBut = BUTTON_CreateEx(97, 45, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_CANCEL); 00981 BUTTON_SetText(hBut, "No"); 00982 hBut = BUTTON_CreateEx(32, 45, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_OK); 00983 BUTTON_SetText(hBut, "Yes"); 00984 } else { 00985 hBut = BUTTON_CreateEx(64, 45, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_OK); 00986 BUTTON_SetText(hBut, "Ok"); 00987 } 00988 // 00989 // Exec modal dialog 00990 // 00991 WM_SetFocus(hFrame); 00992 WM_MakeModal(hFrame); 00993 r = GUI_ExecCreatedDialog(hFrame); 00994 WM_SetFocus(_hFrame); 00995 return r; 00996 } 00997 00998 /********************************************************************* 00999 * 01000 * Static code, dialog settings 01001 * 01002 ********************************************************************** 01003 */ 01004 /********************************************************************* 01005 * 01006 * _cbDialogSettings 01007 */ 01008 static void _cbDialogSettings(WM_MESSAGE * pMsg) { 01009 WM_HWIN hItem; 01010 WM_HWIN hWin; 01011 01012 hWin = pMsg->hWin; 01013 switch (pMsg->MsgId) { 01014 case WM_NOTIFY_PARENT: 01015 if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) { 01016 hItem = pMsg->hWinSrc; 01017 switch (WM_GetId(hItem)) { 01018 case GUI_ID_OK: 01019 GUI_EndDialog(hWin, 1); 01020 break; 01021 case GUI_ID_CHECK0: 01022 _ShowPossibleMoves = CHECKBOX_GetState(hItem); 01023 _InvalidateBoard(); 01024 break; 01025 } 01026 } 01027 break; 01028 default: 01029 WM_DefaultProc(pMsg); 01030 } 01031 } 01032 01033 /********************************************************************* 01034 * 01035 * _ShowDialogSettings 01036 */ 01037 static void _ShowDialogSettings(void) { 01038 WM_HWIN hClient; 01039 WM_HWIN hFrame; 01040 WM_HWIN hItem; 01041 01042 // 01043 // Create framewin 01044 // 01045 hFrame = FRAMEWIN_CreateEx(70, 75, 180, 90, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "Game settings", _cbDialogSettings); 01046 FRAMEWIN_SetClientColor (hFrame, GUI_WHITE); 01047 FRAMEWIN_SetFont (hFrame, &GUI_Font10_1); 01048 FRAMEWIN_SetTextAlign (hFrame, GUI_TA_HCENTER); 01049 // 01050 // Create dialog items 01051 // 01052 hClient = WM_GetClientWindow(hFrame); 01053 // 01054 // Create button 01055 // 01056 hItem = BUTTON_CreateEx(59, 46, 55, 18, hClient, WM_CF_SHOW, 0, GUI_ID_OK); 01057 BUTTON_SetText(hItem, "Ok"); 01058 // 01059 // Create checkbox 01060 // 01061 hItem = CHECKBOX_CreateEx(10, 10, 140, 0, hClient, WM_CF_SHOW, 0, GUI_ID_CHECK0); 01062 CHECKBOX_SetText (hItem, "Show possible moves"); 01063 CHECKBOX_SetBkColor(hItem, GUI_INVALID_COLOR); 01064 CHECKBOX_SetState (hItem, _ShowPossibleMoves); 01065 // 01066 // Exec modal dialog 01067 // 01068 WM_SetFocus (hFrame); 01069 WM_MakeModal (hFrame); 01070 GUI_ExecCreatedDialog(hFrame); 01071 WM_SetFocus (_hFrame); 01072 } 01073 01074 /********************************************************************* 01075 * 01076 * Static code 01077 * 01078 ********************************************************************** 01079 */ 01080 /********************************************************************* 01081 * 01082 * _SetPlayer 01083 */ 01084 static void _SetPlayer(int Player) { 01085 char ac[256]; 01086 int PossibleMoves; 01087 int ValidMoves; 01088 int Score; 01089 01090 _Board.ActPlayer = Player; 01091 if (Player == 1) { 01092 FRAMEWIN_SetText(_hFrame, "Reversi - Player 1"); 01093 } else { 01094 FRAMEWIN_SetText(_hFrame, "Reversi - Player 2"); 01095 } 01096 FRAMEWIN_SetBarColor(_hFrame, 1, (Player == 1) ? GUI_RED : GUI_BLUE); 01097 PossibleMoves = _CalcValidMoves(&_Board); 01098 GUI_Exec(); 01099 if (!PossibleMoves) { 01100 GUI_Exec(); 01101 _Board.ActPlayer = 3 - Player; 01102 ValidMoves = _CalcValidMoves(&_Board); 01103 _Board.ActPlayer = Player; 01104 _CalcValidMoves(&_Board); 01105 if (ValidMoves) { 01106 if (_pPlayerAI[_Board.ActPlayer - 1] == NULL) { 01107 // 01108 // No valid moves, player must pass 01109 // 01110 _ShowMessageBox("Reversi", "No possible moves.\nYou have to pass!", 0); 01111 } 01112 _SetPlayer(3 - _Board.ActPlayer); 01113 } else { 01114 // 01115 // No valid moves for all players, game is over 01116 // 01117 _GameOver = 1; 01118 _Board.ActPlayer = 1; 01119 Score = _CalcScore(&_Board); 01120 if (Score > 0) { 01121 sprintf(ac, "Red wins by %d stones!\nDo you want to start a new game?", Score); 01122 } else if (Score) { 01123 sprintf(ac, "Blue wins by %d stones!\nDo you want to start a new game?", -Score); 01124 } else { 01125 strcpy (ac, "The game ends in a draw!\nDo you want to start a new game?"); 01126 } 01127 if (_ShowMessageBox("Reversi", ac, 1)) { 01128 _StartNewGame(); 01129 } 01130 } 01131 } 01132 } 01133 01134 /********************************************************************* 01135 * 01136 * _NextPlayer 01137 */ 01138 static void _NextPlayer(void) { 01139 char DoMove; 01140 int x; 01141 int y; 01142 01143 do { 01144 _SetPlayer(3 - _Board.ActPlayer); 01145 if (_pPlayerAI[_Board.ActPlayer - 1]&& !_GameOver) { 01146 DoMove = (*_pPlayerAI[_Board.ActPlayer - 1])(&_Board, &x, &y); 01147 if (DoMove) { 01148 _MakeMove(&_Board, x, y); 01149 } 01150 } 01151 } while (_pPlayerAI[_Board.ActPlayer - 1] && !_GameOver); 01152 } 01153 01154 /********************************************************************* 01155 * 01156 * _StartNewGame 01157 */ 01158 static void _StartNewGame(void) { 01159 memset(&_Board, 0, sizeof(BOARD)); 01160 _Board.aCells[3][3] = 1; 01161 _Board.aCells[4][4] = 1; 01162 _Board.aCells[3][4] = 2; 01163 _Board.aCells[4][3] = 2; 01164 _GameOver = 0; 01165 _SetPlayer(1); 01166 _InvalidateBoard(); 01167 } 01168 01169 /********************************************************************* 01170 * 01171 * _HandlePID 01172 */ 01173 static void _HandlePID(int x, int y, int Pressed) { 01174 static int IsInHandlePID = 0; 01175 unsigned ReleaseCapture; 01176 01177 ReleaseCapture = 1; 01178 if (IsInHandlePID++ == 0) { 01179 _CalcBoardDimensions(); 01180 x -= _BoardX0; 01181 y -= _BoardY0; 01182 if ((x >= 0) && (y >= 0)) { 01183 x /= _CellSize; 01184 y /= _CellSize; 01185 if ((x < 8) && (y < 8)) { 01186 if (_IsValidMove(&_Board, x, y)) { 01187 if (Pressed == 0) { 01188 _ReleaseCapture(); 01189 _MakeMove(&_Board, x, y); 01190 _NextPlayer(); 01191 } else { 01192 _SetCapture(); 01193 } 01194 ReleaseCapture = 0; 01195 } 01196 } 01197 } 01198 if (ReleaseCapture) { 01199 _ReleaseCapture(); 01200 } 01201 } 01202 IsInHandlePID--; 01203 } 01204 01205 /********************************************************************* 01206 * 01207 * _OnTouch 01208 */ 01209 static void _OnTouch(WM_MESSAGE * pMsg) { 01210 const GUI_PID_STATE * pState; 01211 01212 pState = (const GUI_PID_STATE *)pMsg->Data.p; 01213 if (pState) { 01214 // 01215 // Something happened in our area (pressed or released) 01216 // 01217 _HandlePID(pState->x, pState->y, pState->Pressed); 01218 } 01219 } 01220 01221 /********************************************************************* 01222 * 01223 * _OnMouseOver 01224 */ 01225 #if (GUI_SUPPORT_MOUSE & GUI_SUPPORT_CURSOR) 01226 static void _OnMouseOver(WM_MESSAGE * pMsg) { 01227 const GUI_PID_STATE * pState; 01228 01229 pState = (const GUI_PID_STATE *)pMsg->Data.p; 01230 if (pState) { 01231 _HandlePID(pState->x, pState->y, -1); 01232 } 01233 } 01234 #endif 01235 01236 /********************************************************************* 01237 * 01238 * _OnMenu 01239 */ 01240 static void _OnMenu(WM_MESSAGE * pMsg) { 01241 MENU_MSG_DATA * pData; 01242 MENU_Handle hMenu; 01243 01244 pData = (MENU_MSG_DATA *)pMsg->Data.p; 01245 hMenu = pMsg->hWinSrc; 01246 switch (pData->MsgType) { 01247 case MENU_ON_INITMENU: 01248 if (_GameOver) { 01249 MENU_DisableItem(hMenu, ID_MENU_PASS); 01250 } else { 01251 MENU_EnableItem(hMenu, ID_MENU_PASS); 01252 } 01253 break; 01254 case MENU_ON_ITEMSELECT: 01255 switch (pData->ItemId) { 01256 case ID_MENU_NEW: 01257 _StartNewGame(); 01258 break; 01259 case ID_MENU_PASS: 01260 _NextPlayer(); 01261 break; 01262 case ID_MENU_EXIT: 01263 WM_DeleteWindow(_hFrame); 01264 break; 01265 case ID_MENU_SETTINGS: 01266 _ShowDialogSettings(); 01267 break; 01268 case ID_MENU_ABOUT: 01269 _ShowAboutBox(); 01270 break; 01271 case ID_MENU_TEST: 01272 WM_ReleaseCapture(); 01273 break; 01274 } 01275 break; 01276 default: 01277 WM_DefaultProc(pMsg); 01278 } 01279 } 01280 01281 /********************************************************************* 01282 * 01283 * _OnPaint 01284 */ 01285 static void _OnPaint(WM_HWIN hWin) { 01286 GUI_COLOR Color; 01287 GUI_RECT Rect; 01288 unsigned rStone; 01289 unsigned rMove; 01290 char IsValidMove; 01291 char Cell; 01292 int CellSize; 01293 int xCircle; 01294 int yCircle; 01295 int xPos; 01296 int yPos; 01297 int x; 01298 int y; 01299 01300 _CalcBoardDimensions(); 01301 GUI_AA_SetFactor(AA_FACTOR); 01302 #if AA_USE_HIRES 01303 GUI_AA_EnableHiRes(); 01304 #endif 01305 LCD_SetBkColor(CLIENT_COLOR); 01306 WM_GetClientRectEx(hWin, &Rect); 01307 GUI_ClearRect(Rect.x0, Rect.y0, Rect.x1, _BoardY0 - 1); 01308 GUI_ClearRect(Rect.x0, _BoardY0, _BoardX0 - 1, _BoardY0 + (8 * _CellSize)); 01309 GUI_ClearRect(_BoardX0 + (8 * _CellSize) + 1, _BoardY0, Rect.x1, _BoardY0 + (8 * _CellSize)); 01310 GUI_ClearRect(Rect.x0, _BoardY0 + (8 * _CellSize) + 1, Rect.x1, Rect.y1); 01311 CellSize = _CellSize - 1; 01312 rStone = ((CellSize - 3) * AA_CALCFACTOR) >> 1; 01313 rMove = ((CellSize - 2) * AA_CALCFACTOR) >> 3; 01314 if (rStone < AA_CALCFACTOR) { 01315 rStone = AA_CALCFACTOR; 01316 } 01317 if (rMove < (AA_CALCFACTOR >> AA_USE_HIRES)) { 01318 rMove = (AA_CALCFACTOR >> AA_USE_HIRES); 01319 } 01320 yPos = _BoardY0; 01321 for (y = 0; y < 8; y++) { 01322 xPos = _BoardX0; 01323 for (x = 0; x < 8; x++) { 01324 Color = ((x + (y & 1)) & 1) ? GUI_LIGHTGRAY : GUI_WHITE; 01325 LCD_SetColor(Color); 01326 GUI_FillRect(xPos + 1, yPos + 1, xPos + CellSize, yPos + CellSize); 01327 Cell = _GetStone(&_Board, x, y); 01328 IsValidMove = (_ShowPossibleMoves) ? _IsValidMove(&_Board, x, y) : 0; 01329 if (_pPlayerAI[_Board.ActPlayer - 1]) { 01330 IsValidMove = 0; 01331 } 01332 if (Cell || IsValidMove) { 01333 xCircle = (xPos + 1) * AA_CALCFACTOR + ((CellSize * AA_CALCFACTOR) >> 1); 01334 yCircle = (yPos + 1) * AA_CALCFACTOR + ((CellSize * AA_CALCFACTOR) >> 1); 01335 if (Cell) { 01336 Color = (Cell == 1) ? (GUI_RED) : (GUI_BLUE); 01337 LCD_SetColor(Color); 01338 #if (AA_FACTOR > 1) 01339 GUI_AA_FillCircle(xCircle, yCircle, rStone); 01340 #else 01341 GUI_FillCircle(xCircle, yCircle, rStone); 01342 #endif 01343 } else { 01344 LCD_SetColor(GUI_BLACK); 01345 #if (AA_FACTOR > 1) 01346 GUI_AA_FillCircle(xCircle, yCircle, rMove); 01347 #else 01348 GUI_FillCircle(xCircle, yCircle, rMove); 01349 #endif 01350 } 01351 } 01352 LCD_SetColor(GRID_COLOR); 01353 GUI_DrawVLine(xPos, yPos + 1, yPos + CellSize); 01354 xPos += _CellSize; 01355 } 01356 GUI_DrawVLine(xPos, yPos + 1, yPos + CellSize); 01357 GUI_DrawHLine(yPos, _BoardX0, _BoardX0 + _CellSize * 8); 01358 yPos += _CellSize; 01359 } 01360 GUI_DrawHLine(yPos, _BoardX0, _BoardX0 + _CellSize * 8); 01361 } 01362 01363 /********************************************************************* 01364 * 01365 * _cbReversiWin 01366 */ 01367 static void _cbReversiWin(WM_MESSAGE * pMsg) { 01368 WM_HWIN hWin; 01369 01370 hWin = pMsg->hWin; 01371 switch (pMsg->MsgId) { 01372 case WM_PAINT: 01373 _OnPaint(hWin); 01374 break; 01375 case WM_TOUCH: 01376 _OnTouch(pMsg); 01377 break; 01378 #if (GUI_SUPPORT_MOUSE & GUI_SUPPORT_CURSOR) 01379 case WM_MOUSEOVER: 01380 _OnMouseOver(pMsg); 01381 break; 01382 #endif 01383 case WM_MENU: 01384 _OnMenu(pMsg); 01385 break; 01386 case WM_DELETE: 01387 _hFrame = 0; 01388 break; 01389 default: 01390 WM_DefaultProc(pMsg); 01391 } 01392 } 01393 01394 /********************************************************************* 01395 * 01396 * _StartReversi 01397 */ 01398 static void _StartReversi(void) { 01399 _hFrame = FRAMEWIN_CreateEx(64, 11, 191, 218, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, NULL, _cbReversiWin); 01400 FRAMEWIN_SetClientColor(_hFrame, GUI_INVALID_COLOR); 01401 FRAMEWIN_SetFont (_hFrame, &GUI_Font10_1); 01402 FRAMEWIN_SetTextAlign (_hFrame, GUI_TA_HCENTER); 01403 FRAMEWIN_AddCloseButton(_hFrame, FRAMEWIN_BUTTON_LEFT, 0); 01404 FRAMEWIN_AddMaxButton (_hFrame, FRAMEWIN_BUTTON_RIGHT, 0); 01405 FRAMEWIN_AddMinButton (_hFrame, FRAMEWIN_BUTTON_RIGHT, 1); 01406 FRAMEWIN_SetResizeable (_hFrame, 1); 01407 _CreateMenu(_hFrame); 01408 _StartNewGame(); 01409 WM_SetFocus(_hFrame); 01410 while (_hFrame) { 01411 GUI_Delay(100); 01412 } 01413 } 01414 01415 /********************************************************************* 01416 * 01417 * Public code 01418 * 01419 ********************************************************************** 01420 */ 01421 /********************************************************************* 01422 * 01423 * MainTask 01424 */ 01425 void MainTask(void) { 01426 WM_SetCreateFlags(WM_CF_MEMDEV); // Use memory devices on all windows to avoid flicker 01427 GUI_Init(); 01428 // 01429 // Check if recommended memory for the sample is available 01430 // 01431 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 01432 GUI_ErrorOut("Not enough memory available."); 01433 return; 01434 } 01435 GUI_CURSOR_Select(&GUI_CursorArrowM); 01436 GUI_CURSOR_Show(); 01437 WM_SetDesktopColor(DESKTOP_COLOR); 01438 _pPlayerAI[1] = AI_FUNC; 01439 while (1) { 01440 _StartReversi(); 01441 GUI_Delay(1000); 01442 } 01443 } 01444 01445 /*************************** End of file ****************************/
Generated on Thu Jul 14 2022 12:58:38 by
