Skip to content

Commit

Permalink
Update regarding generated binaries option
Browse files Browse the repository at this point in the history
Moved asset folder to project directory. Changed the file paths to absolute file paths. Added icon file. Added scripts to generate binaries using pyinstaller.
  • Loading branch information
MegatronJeremy committed Jul 13, 2024
1 parent 6fee9ed commit b229325
Show file tree
Hide file tree
Showing 39 changed files with 90 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ __pycache__/

# Distribution / packaging
.Python
output/
build/
develop-eggs/
dist/
Expand Down
Empty file removed __init__.py
Empty file.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
17 changes: 17 additions & 0 deletions generate_binaries.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@echo off
REM Check if PowerShell script exists
if not exist generate_binaries.ps1 (
echo generate_binaries.ps1 does not exist.
exit /b 1
)

REM Run the PowerShell script
powershell.exe -NoProfile -ExecutionPolicy Bypass -File generate_binaries.ps1

REM Check if the PowerShell script ran successfully
if %errorlevel% neq 0 (
echo PowerShell script generate_binaries.ps1 failed.
exit /b 1
)

echo PowerShell script generate_binaries.ps1 ran successfully.
21 changes: 21 additions & 0 deletions generate_binaries.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Display menu options
Write-Host "Select an option:"
Write-Host "1. Run command for One Directory"
Write-Host "2. Run command for One File"

# Read user input
$userChoice = Read-Host "Enter your choice (1 or 2)"

# Process user choice
switch ($userChoice)
{
1 {
pyinstaller --noconfirm --onedir --console --icon "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\icon.ico" --name "team_segfault" --optimize "2" --add-data "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\assets;assets/" --add-data "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\mab\data\server_data;mab/data/server_data/" --add-data "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\mab\data\training_data;mab/data/training_data/" "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\main.py"
}
2 {
pyinstaller --noconfirm --onefile --console --icon "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\icon.ico" --name "team_segfault" --optimize "2" --add-data "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\assets;assets/" --add-data "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\mab\data\server_data;mab/data/server_data/" --add-data "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\mab\data\training_data;mab/data/training_data/" "C:\Users\xparh\OneDrive\Desktop\Team-Segfault\main.py"
}
default {
Write-Host "Invalid choice. Please enter 1 or 2."
}
}
Binary file added icon.ico
Binary file not shown.
22 changes: 13 additions & 9 deletions mab/data/data_io.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json
import os
from typing import Type


class DataIO:
__training_data_path = "mab\\data\\training_data\\"
__script_path = os.path.dirname(__file__)

__client_map_path = "mab\\data\\server_data\\client_map"
__game_state_path = "mab\\data\\server_data\\game_state"
__training_data_path = os.path.join(__script_path, "training_data")

__client_map_path = os.path.join(__script_path, "server_data/client_map")
__game_state_path = os.path.join(__script_path, "server_data/game_state")

ResultsTable = Type[dict[int, dict[str, list[int]]]]

Expand Down Expand Up @@ -66,25 +69,26 @@ def save_game_state(game_state: dict) -> None:

@staticmethod
def load_results_table(save_file: str) -> ResultsTable:
return DataIO.__load(DataIO.__training_data_path + save_file + '_results_table')
return DataIO.__load(DataIO.__training_data_path + '\\' + save_file + '_results_table')

@staticmethod
def load_num_games(save_file: str) -> int:
return DataIO.__load(DataIO.__training_data_path + save_file + '_num_games')
return DataIO.__load(DataIO.__training_data_path + '\\' + save_file + '_num_games')

@staticmethod
def load_best_actions(save_file: str) -> dict[int, str]:
return DataIO.__load(DataIO.__training_data_path + save_file + '_best_actions')
return DataIO.__load(DataIO.__training_data_path + '\\' + save_file + '_best_actions')

@staticmethod
def load_client_map() -> dict: return DataIO.__load(DataIO.__client_map_path)
def load_client_map() -> dict:
return DataIO.__load(DataIO.__client_map_path)

@staticmethod
def load_game_state() -> dict: return DataIO.__load(DataIO.__game_state_path)
def load_game_state() -> dict:
return DataIO.__load(DataIO.__game_state_path)

@staticmethod
def __load(from_where: str):
with open(from_where + '.json', 'r') as file:
what = json.load(file)
return what

67 changes: 38 additions & 29 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,50 @@
SOUND_VOLUME = [0.0]
MAX_PLAYERS = 3
DEFAULT_NUM_TURNS = 45

import os

# get the directory where the current script is located
SCRIPT_DIR = os.path.dirname(__file__)

# define the base directory for the assets
ASSETS_LOCATION = os.path.join(SCRIPT_DIR, '../assets')

# sound paths
EXPLOSION_SOUND = 'src/assets/sounds/explosion.mp3'
BULLET_SOUND = 'src/assets/sounds/shot.mp3'
EXPLOSION_SOUND = os.path.join(ASSETS_LOCATION, 'sounds', 'explosion.mp3')
BULLET_SOUND = os.path.join(ASSETS_LOCATION, 'sounds', 'shot.mp3')

# font paths
MENU_FONT = 'src/assets/menu/BrunoAceSC-Regular.ttf'
# font path
MENU_FONT = os.path.join(ASSETS_LOCATION, 'menu', 'BrunoAceSC-Regular.ttf')

# image paths
TANK_ICON_PATH = 'src/assets/tank_icon.png'
SPG_IMAGE_PATH = 'src/assets/tank_classes/spg.png'
HT_IMAGE_PATH = 'src/assets/tank_classes/ht.png'
LT_IMAGE_PATH = 'src/assets/tank_classes/lt.png'
MT_IMAGE_PATH = 'src/assets/tank_classes/mt.png'
TD_IMAGE_PATH = 'src/assets/tank_classes/td.png'

CATAPULT_IMAGE_PATH = 'src/assets/bonuses/catapult.png'
LIGHT_REPAIR_IMAGE_PATH = 'src/assets/bonuses/light_repair.png'
HARD_REPAIR_IMAGE_PATH = 'src/assets/bonuses/hard_repair.png'

FLAG_PATH = 'src/assets/flag.png'
EXPLOSION_IMAGES = [f'src/assets/explosion_images/{i}.png' for i in range(7)]
BULLET_IMAGE_PATH = 'src/assets/white_bullet.png'

BACKGROUND_IMAGE_PATH = 'src/assets/menu/background.jpg'
GUI_ICON_PATH = 'src/assets/icon.png'
TRACKS_IMAGE_PATH = 'src/assets/tracks_green.png'
TROPHY_IMAGE_PATH = 'src/assets/trophy.png'
TANK_ICON_PATH = os.path.join(ASSETS_LOCATION, 'tank_icon.png')
SPG_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'tank_classes', 'spg.png')
HT_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'tank_classes', 'ht.png')
LT_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'tank_classes', 'lt.png')
MT_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'tank_classes', 'mt.png')
TD_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'tank_classes', 'td.png')

CATAPULT_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'bonuses', 'catapult.png')
LIGHT_REPAIR_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'bonuses', 'light_repair.png')
HARD_REPAIR_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'bonuses', 'hard_repair.png')

FLAG_PATH = os.path.join(ASSETS_LOCATION, 'flag.png')
EXPLOSION_IMAGES = [os.path.join(ASSETS_LOCATION, 'explosion_images', f'{i}.png') for i in range(7)]
BULLET_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'white_bullet.png')

BACKGROUND_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'menu', 'background.jpg')
GUI_ICON_PATH = os.path.join(ASSETS_LOCATION, 'icon.png')
TRACKS_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'tracks_green.png')
TROPHY_IMAGE_PATH = os.path.join(ASSETS_LOCATION, 'trophy.png')

# map hexes
SUMMER_GRASS_PATH = 'src/assets/hex_images/summer_empty.png'
SUMMER_OBSTACLE_PATH = 'src/assets/hex_images/summer_obstacle.png'
DESERT_EMPTY_PATH = 'src/assets/hex_images/desert_empty.png'
DESERT_OBSTACLE_PATH = 'src/assets/hex_images/desert_obstacle.png'
WINTER_EMPTY_PATH = 'src/assets/hex_images/winter_empty.png'
WINTER_OBSTACLE_PATH = 'src/assets/hex_images/winter_obstacle.png'
SUMMER_GRASS_PATH = os.path.join(ASSETS_LOCATION, 'hex_images', 'summer_empty.png')
SUMMER_OBSTACLE_PATH = os.path.join(ASSETS_LOCATION, 'hex_images', 'summer_obstacle.png')
DESERT_EMPTY_PATH = os.path.join(ASSETS_LOCATION, 'hex_images', 'desert_empty.png')
DESERT_OBSTACLE_PATH = os.path.join(ASSETS_LOCATION, 'hex_images', 'desert_obstacle.png')
WINTER_EMPTY_PATH = os.path.join(ASSETS_LOCATION, 'hex_images', 'winter_empty.png')
WINTER_OBSTACLE_PATH = os.path.join(ASSETS_LOCATION, 'hex_images', 'winter_obstacle.png')

# other
BULLET_VECTOR = (1, 0)
Expand Down

0 comments on commit b229325

Please sign in to comment.