Skip to content

Commit

Permalink
Merge pull request #15 from danlangford/14-ornery-dice-rerolls
Browse files Browse the repository at this point in the history
14 ornery dice rerolls
  • Loading branch information
pappde authored Feb 26, 2021
2 parents d8913b0 + f82f7df commit da975ce
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 29 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CMake

on: [push]
on: [push, pull_request]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -18,26 +18,24 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Get latest CMake and ninja
uses: lukka/get-cmake@latest

- name: Configure CMake
- name: CMake Configure
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
working-directory: ${{runner.workspace}}
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake -S $GITHUB_WORKSPACE -B build

- name: Build
working-directory: ${{runner.workspace}}/build
- name: CMake Build
working-directory: ${{runner.workspace}}
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
run: cmake --build build --config $BUILD_TYPE

- name: Test
working-directory: ${{runner.workspace}}/build
Expand Down
31 changes: 30 additions & 1 deletion BUILDING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,33 @@ mkdir build
cd build
cmake ..
devenv bmai.sln /build
```
```


------

UPDATE: I have learned about a more modern apporach to using CMake. There are 2 patterns that are becoming common.

For command line only builds
```sh
echo configuring Debug and Release dirs
cmake -S . -B build/Debug -D CMAKE_BUILD_TYPE=Debug
cmake -S . -B build/Release -D CMAKE_BUILD_TYPE=Release

echo building Debug and Release binaries
cmake --build build/Debug
cmake --build build/Release
```

and for a multi-config / IDE based approach
```sh
echo configuring build dir
cmake -S . -B build
echo you can point your IDE at build/ dir

echo or build from command line
cmake --build build --config Debug
echo for a subsequent Release build you will need to rebuild the build/ dir
cmake -S . -B build
echo --build build --config Release
```
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@
cmake_minimum_required (VERSION 3.8)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# to be able to reference header files
include_directories(./src)
project(bmai)

# to collect only needed source files
set(SOURCE ./src/bmai.cpp ./src/bmai_ai.cpp ./src/bmai_player.cpp)

add_executable(${PROJECT_NAME} ${SOURCE})
# some IDEs really need the Headers added to the executable
# to be able to index everything correctly
set(HEADERS ./src/bmai.h ./src/bmai_ai.h)

add_executable(${PROJECT_NAME} ${SOURCE} ${HEADERS})

# to be able to reference header files
target_include_directories(${PROJECT_NAME} PRIVATE ./src)

# remove ZERO_CHECK build
set(CMAKE_SUPPRESS_REGENERATION true)

# HIDE away ALL_BUILD in VS
# for Xcode see https://gitlab.kitware.com/cmake/cmake/-/issues/21853
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
33 changes: 20 additions & 13 deletions src/bmai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@
// definitions
BME_ATTACK_TYPE g_attack_type[BME_ATTACK_MAX] =
{
BME_ATTACK_TYPE_1_1,
BME_ATTACK_TYPE_N_1,
BME_ATTACK_TYPE_1_N,
BME_ATTACK_TYPE_1_N,
BME_ATTACK_TYPE_1_1,
BME_ATTACK_TYPE_1_1,
BME_ATTACK_TYPE_0_0,
BME_ATTACK_TYPE_1_1, // FIRST & POWER 1:1
BME_ATTACK_TYPE_N_1, // SKILL N:1
BME_ATTACK_TYPE_1_N, // BERSERK
BME_ATTACK_TYPE_1_N, // SPEED
BME_ATTACK_TYPE_1_1, // TRIP
BME_ATTACK_TYPE_1_1, // SHADOW
BME_ATTACK_TYPE_0_0, // INVALID
};

// MOOD dice - from BM page:
Expand Down Expand Up @@ -840,6 +840,9 @@ float BMC_Die::GetScore(bool _own)
// PARAM: _actually_attacking is normally true, but may be false for forced attack rerolls like ORNERY
void BMC_Die::OnApplyAttackPlayer(BMC_Move &_move, BMC_Player *_owner, bool _actually_attacking)
{
// TODO determine how this may conflict with the design of `bool _actually_attacking`
BM_ASSERT(g_attack_type[_move.m_attack]!=BME_ATTACK_TYPE_0_0);

// clear value
// KONSTANT: don't reroll
if (!HasProperty(BME_PROPERTY_KONSTANT))
Expand Down Expand Up @@ -2677,12 +2680,16 @@ void BMC_Game::ApplyAttackPlayer(BMC_Move &_move)
}

// ORNERY: all ornery dice on attacker must reroll (whether or not attacked)
for (i=0; i<attacker->GetAvailableDice(); i++)
{
att_die = attacker->GetDie(i);
if (att_die->HasProperty(BME_PROPERTY_ORNERY))
att_die->OnApplyAttackPlayer(_move,attacker,false); // false means not _actually_attacking
}
// unless the player passed (there must be SOME attack involved)
if (_move.m_attack != BME_ATTACK_INVALID)
{
for (i=0; i<attacker->GetAvailableDice(); i++)
{
att_die = attacker->GetDie(i);
if (att_die->HasProperty(BME_PROPERTY_ORNERY))
att_die->OnApplyAttackPlayer(_move,attacker,false); // false means not _actually_attacking
}
}
}

// DESC: simulate all random steps - reroll attackers, targets, MOOD
Expand Down
2 changes: 1 addition & 1 deletion src/bmai.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ enum BME_ATTACK
BME_ATTACK_FIRST = 0,
BME_ATTACK_POWER = BME_ATTACK_FIRST, // 1 -> 1
BME_ATTACK_SKILL, // N -> 1
BME_ATTACK_BERSERK, // N -> 1
BME_ATTACK_BERSERK, // 1 -> N
BME_ATTACK_SPEED, // 1 -> N
BME_ATTACK_TRIP, // 1 -> 1
BME_ATTACK_SHADOW, // 1 -> 1
Expand Down

0 comments on commit da975ce

Please sign in to comment.