-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into packaging
- Loading branch information
Showing
15 changed files
with
293 additions
and
27 deletions.
There are no files selected for viewing
Binary file modified
BIN
-411 Bytes
(100%)
Content/EmptierThanVoid/UI/HUD/WBP_GameUI_ShipStatus.uasset
Binary file not shown.
Binary file modified
BIN
+1.9 KB
(100%)
Content/EmptierThanVoid/UI/HUD/WPB_ActionDeathLogEntry.uasset
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright (C) Team13. All rights reserved. | ||
|
||
#include "ETVAI.h" | ||
#include "ETVGameModeBase.h" | ||
#include "ETVActionTarget_Fire.h" | ||
#include "ETVActionTarget_Move.h" | ||
|
||
// TODO Returns duplicate objects of all the ships on the board for AI to calculate the next move | ||
TArray<AETVShip*> GetBoardStateClone(TArray<AETVShip*> BoardState) | ||
{ | ||
TArray<AETVShip*> Clones; | ||
for(auto ShipRef : BoardState) | ||
{ | ||
// Check for class? | ||
|
||
// Cast and create clone | ||
|
||
// Get clone's reference | ||
|
||
// Push reference to clones | ||
|
||
} | ||
return Clones; | ||
} | ||
|
||
// TODO Calculates maximum score and the coresponding board state if the given ship makes a move | ||
TArray<AETVShip*> GetNextBoardStateAndScore(TArray<AETVShip*> BoardState, int32 ShipIndex, TArray<TArray<int32>> &MoveInstructions) | ||
{ | ||
return TArray<AETVShip*>(); | ||
} | ||
|
||
// TODO Returns the 5 best moves for the given boardState | ||
TArray<TArray<AETVShip*>> GetTop5Moves(TArray<AETVShip*> BoardState, TArray<TArray<int32>> &MoveInstructions) | ||
{ | ||
return TArray<TArray<AETVShip*>>(); | ||
} | ||
|
||
|
||
UETVAI::UETVAI() | ||
{ | ||
|
||
} | ||
// TODO Better Implementation | ||
TArray<int32> UETVAI::GetMove(TArray<AETVShip*> Ships) | ||
{ | ||
TArray<int32> MoveInstructions; | ||
|
||
// Get gamemode | ||
AETVGameModeBase* GameMode = Cast<AETVGameModeBase>(Ships[0]->GetWorld()->GetAuthGameMode()); | ||
|
||
int32 MostImportantPlayerShip = -1; | ||
int32 MostImportantAIShip = -1; | ||
int32 RandomAIShip = -1; | ||
// Find most important ships | ||
int index = 0; | ||
for (auto ShipReference : Ships) | ||
{ | ||
// AI Ship | ||
if (ShipReference->IsEnemy()) | ||
{ | ||
if (MostImportantAIShip != -1) | ||
{ | ||
// This will always be the capital | ||
if (ShipReference->GetScore() > Ships[MostImportantAIShip]->GetScore()) | ||
{ | ||
MostImportantAIShip = index; | ||
} | ||
} | ||
else | ||
{ | ||
MostImportantAIShip = index; | ||
RandomAIShip = index; | ||
} | ||
// 1/8 chance | ||
if (FMath::RandBool() && FMath::RandBool() && FMath::RandBool()) | ||
{ | ||
RandomAIShip = index; | ||
} | ||
} | ||
else if (GameMode->IsTileVisible(ShipReference->GetTilePosition(), EETVShipType::EnemyShip) == true) | ||
{ | ||
if (MostImportantPlayerShip != -1) | ||
{ | ||
if (ShipReference->GetScore() > Ships[MostImportantPlayerShip]->GetScore()) | ||
{ | ||
MostImportantPlayerShip = index; | ||
} | ||
} | ||
else | ||
{ | ||
MostImportantPlayerShip = index; | ||
} | ||
} | ||
++index; | ||
} | ||
// Does AI see enemy ship | ||
if (MostImportantPlayerShip != -1) | ||
{ | ||
int jndex = 0; | ||
// If possible try and attack | ||
for (auto ShipReference : Ships) | ||
{ | ||
if (ShipReference->IsEnemy()) | ||
{ | ||
// Currently fire laser is always 0 and torpedo is 1 on fighters | ||
int ActionIndex = 0; | ||
if(ShipReference->GetShipClass() == "Fighter" || ShipReference->GetShipClass() == "Capital") | ||
ActionIndex = 1; | ||
UETVActionTarget_Fire* Laser = Cast<UETVActionTarget_Fire>(ShipReference->GetActions()[ActionIndex]); | ||
// TODO - Add check if torped avaliable | ||
Laser->SetTarget(Ships[MostImportantPlayerShip], Ships[MostImportantPlayerShip]->GetX(), Ships[MostImportantPlayerShip]->GetY()); | ||
if (Laser->CanPerform()) | ||
{ | ||
MoveInstructions.SetNum(4); | ||
MoveInstructions[0] = (Ships[MostImportantPlayerShip]->GetScore()); | ||
MoveInstructions[1] = (jndex); | ||
MoveInstructions[2] = (ActionIndex); | ||
MoveInstructions[3] = (MostImportantPlayerShip); | ||
return MoveInstructions; | ||
} | ||
} | ||
++jndex; | ||
} | ||
} | ||
// We we didn't find enemy ship or we can't attack it | ||
// We move a ship randomly | ||
// TODO Add checker if we can heal most important ship | ||
UETVActionTarget_Move* MoveAction = Cast<UETVActionTarget_Move>(Ships[RandomAIShip]->GetActions().Last(0)); | ||
int x = -1; | ||
int y = -1; | ||
while (!MoveAction->CanPerform()) | ||
{ | ||
x = Ships[RandomAIShip]->GetTilePosition().X + FMath::RandRange(1, Ships[RandomAIShip]->GetMoveRange()); | ||
y = Ships[RandomAIShip]->GetTilePosition().Y + FMath::RandRange(1, Ships[RandomAIShip]->GetMoveRange()); | ||
MoveAction->SetTarget(GameMode->GetTileMapActor(), x, y); | ||
} | ||
MoveInstructions.SetNum(5); | ||
MoveInstructions[0] = (Ships[RandomAIShip]->GetScore()); | ||
MoveInstructions[1] = (RandomAIShip); | ||
MoveInstructions[2] = (Ships[RandomAIShip]->GetActions().Num()-1); | ||
MoveInstructions[3] = (x); | ||
MoveInstructions[4] = (y); | ||
return MoveInstructions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) Team13. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
#include "UObject/NoExportTypes.h" | ||
#include "ETVShip.h" | ||
#include "ETVAI.generated.h" | ||
|
||
/** | ||
* Class that contains all the logic for the AI in the game | ||
* It passes move instructions to the game mode in a form of An Array of int32 Arrays, where ints represent ship indexes, | ||
* action indexesm coordinates or traget ship indexes and the board state if this move is used, 1 array of this ints represents 1 posssible move | ||
* -------------------------------------------- | ||
* 0: Score | ||
* 1: Ship index | ||
* 2: Action index | ||
* 3: Target ship index/X coordinate | ||
* 4: Y coordinate | ||
* -------------------------------------------- | ||
* If array returned contains 4 ints it can be deduced that the last int represnts an index for the target ship else it represents the X coordinate | ||
* of the board | ||
* -------------------------------------------- | ||
* Ai will look a certain amount of turns into the future, predict the best moves and choose the move that will | ||
* lead to the best outcome in set amount of turns | ||
* -------------------------------------------- | ||
* It currently does not work like this. | ||
* Problems to solve: Dynamic Deep Copying of actors or support for dummy properties in actors that AI can use to calculate board states. | ||
* -------------------------------------------- | ||
* AI currently atack the highes priority target of enemy, heals the ship with highest priority on his sie or moves a ship randomly | ||
* -------------------------------------------- | ||
*/ | ||
UCLASS() | ||
class ETV_API UETVAI : public UObject | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
// Sets default values for this actor's properties | ||
UETVAI(); | ||
|
||
|
||
public: | ||
// Returns the move AI will make this turn depending on the given board state | ||
TArray<int32> GetMove(TArray<AETVShip*> Ships); | ||
|
||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.