File indexing completed on 2024-05-19 04:04:52
0001 /* 0002 This file is part of the game 'KJumpingCube' 0003 0004 SPDX-FileCopyrightText: 1998-2000 Matthias Kiefer <matthias.kiefer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "ai_kepler.h" 0010 0011 AI_Kepler::AI_Kepler() 0012 { 0013 } 0014 0015 int AI_Kepler::assessCube (const int index, const Player player, 0016 const int neighbors [4], const Player owners[], 0017 const int values[], const int maxValues[] 0018 ) const 0019 { 0020 int diff = VeryHighValue; 0021 int temp = VeryHighValue; 0022 int pos = 0; 0023 0024 // Check the neighbors. 0025 for (int i = 0; i < 4; i++) { 0026 if ((pos = neighbors [i]) >= 0) { 0027 temp = (owners [pos] != player) ? maxValues[index] - values[index] 0028 : maxValues[index] - values[index] + 1; 0029 if (temp < diff) { 0030 diff = temp; 0031 } 0032 } 0033 // Else, do nothing: no neighbor on this side. 0034 } 0035 0036 int val; 0037 temp = maxValues[index] - values[index]; 0038 val = diff - temp + 1; 0039 val = val * (temp + 1); 0040 if (val <= 0) { 0041 val = HighValue - val; // Always return values > 0. 0042 } 0043 0044 return val; 0045 }