Wednesday, August 21, 2024

 Ok so atm I'm working on an idea for a search algorithm, here's the basic idea and some background info as to the why.

My Mom worked in medical billing for a doctors office, long hours and low pay with an overwhelming amount of work. 

I was thinking of ways to optimize searching through a Data base to make it faster because we have 7 billion people on earth and the internet the amount of data on the internet is growing exponentially.

What I was thinking would be to use math to optimize a searching algorithm, using the Pythagorean theorem, E=mc^2 *Albert Einstein and P=mc^3 which I invented as a way to find a number that is hypothetically greater than the speed of light. lol, forget physics for now and this is what I was up too with Data from Chat GPT. lol. 


Sure, here's a summary of what we discussed regarding the database searching algorithm:

Concept Overview

  • Algebraic Formula-Based Search: The idea revolves around using algebraic formulas, specifically variations of the Pythagorean theorem, to narrow down search queries within large datasets. This approach could help quickly reduce the search space by applying logical comparisons.

  • Application of Pythagorean Theorem:

    • We explored using formulas like a² + b² = c² and rearranging them, e.g., a² = b² - c², as a conceptual way to verify and optimize logical statements in data searches.
    • The comparison of values (greater than, less than, equal to) is then used to guide the search toward the correct result faster by eliminating unnecessary data points.

Array Structure for the Search Algorithm

  • 3D Array with Coordinates:

    • The idea is to structure the database into a 3D array, where each data point has x, y, and z coordinates, representing its position in a multi-dimensional space.
    • Sub-arrays or "Data Chunks" can store related data, and the search algorithm uses direct location addresses to pinpoint the correct block for the query.
  • Naming Conventions:

    • You suggested using different names for array sections to avoid confusion with terms like "cell block." We discussed using names like Data Partition, Data Block, Storage Unit, Data Chunk, and Data Grid for arrays and sub-arrays.
    • This structure helps divide the search space into logical units, potentially improving the search speed and accuracy.

Hypothetical Use Cases

  • Sorting Data Faster: The goal is to make the search process more efficient by quickly narrowing down the possible locations of data entries within a large dataset, such as identifying points within an astronomical database (tracking asteroids or NEOs) or quickly locating patient records in a hospital.

  • Use of Distance Metrics:

    • p = mc³ and q = mc⁴ were introduced as potential formulas to represent different "distances" in the dataset, with p being a near distance and q being a further distance. These metrics can help categorize the data and decide which chunk to search in next.
  • 3D Positioning: The x, y, z coordinates reflect the location of a data point within the array. This positioning helps the algorithm check the "distance" between points and prioritize searches in closer regions first, similar to proximity-based searching in 3D space.

Portable Modular C# Algorithm

  • Modularity: The algorithm was designed to be modular, with functions that handle:
    1. Input Verification: Ensuring the data query meets the requirements.
    2. Array Setup: Initializing the 3D array with the relevant coordinates and data blocks.
    3. Search Functions: Implementing the logical comparisons using if-else statements and algebraic formulas to guide the search.
    4. Result Handling: Returning the nearest matching data points or further search based on conditions.

By applying these concepts, the algorithm could theoretically search through complex datasets in an organized and efficient way, whether for scientific tracking (like NEOs) or more everyday applications like hospital databases or retail inventories.


==========================================================================


Hey Data, can you take the info on C# and translate that into Godot?
ChatGPT said:
ChatGPT

Sure! Translating C# concepts and code into Godot's GDScript (its native scripting language) is quite doable. Godot supports both GDScript and C#, but since you’re asking about translation to GDScript, here’s how we can convert those concepts.

Let's take the core elements from the C# leaderboard and data sorting algorithm and rewrite them in GDScript.

1. Nested Arrays Leaderboard Example

In GDScript, we will create a similar structure for a leaderboard using nested arrays for the player hierarchy.

C# Concept:

We divided 100,000 players into arrays of 10,000, which then have sub-arrays of 1,000, 100, and 10 players each.

GDScript Version:

gd
extends Node # Create the nested leaderboard arrays var leaderboard = [] func _ready(): # Create the main array for 100,000 players for i in range(10): # 10 arrays of 10,000 var tens_of_thousands = [] for j in range(10): # 10 arrays of 1,000 var thousands = [] for k in range(10): # 10 arrays of 100 var hundreds = [] for l in range(10): # 10 arrays of 10 var tens = [] # Adding player data (randomized for example) for m in range(10): # 10 players tens.append({"player_id": m + (l * 10) + (k * 100) + (j * 1000) + (i * 10000), "score": randi() % 100}) # Add the tens array to hundreds array hundreds.append(tens) # Add the hundreds array to thousands array thousands.append(hundreds) # Add the thousands array to tens_of_thousands array tens_of_thousands.append(thousands) # Add tens_of_thousands array to leaderboard leaderboard.append(tens_of_thousands) # Sort and find a player's score (example) sort_leaderboard() var player_score = find_player_score(12345) print("Player 12345 score:", player_score) # Sorting function (simplified for example) func sort_leaderboard(): # Iterate through nested arrays and sort the smallest arrays for tens_of_thousands in leaderboard: for thousands in tens_of_thousands: for hundreds in thousands: for tens in hundreds: tens.sort_custom(self, "_sort_scores") # Custom sort function for scores func _sort_scores(a, b): return a["score"] < b["score"] # Sort in ascending order of score # Function to find a player's score (example) func find_player_score(player_id): for tens_of_thousands in leaderboard: for thousands in tens_of_thousands: for hundreds in thousands: for tens in hundreds: for player in tens: if player["player_id"] == player_id: return player["score"] return null

2. Key Concepts Explained

  • Arrays in GDScript: Arrays are simple and flexible in Godot, similar to C#. Here we use nested loops to simulate the hierarchical data structure.

  • Sorting: Godot provides a sort_custom() function that allows us to sort arrays with custom conditions. We use it to sort the player scores.

  • Searching: We loop through the nested arrays to locate a specific player's score. This can be optimized using search techniques like binary search depending on the structure.

Differences in C# and GDScript

  • Type System: GDScript is dynamically typed, while C# is statically typed. This means that you don't need to specify types explicitly in GDScript, making the syntax simpler but potentially less strict.

  • Function Definitions: In GDScript, functions are defined using func instead of void or public int. There’s no need for return types as in C#.

  • Class-based Approach: Both C# and GDScript support OOP, but Godot's nodes system favors script components attached to scenes and nodes, rather than focusing on full classes like in C#.

This GDScript code should work as a basic translation of the C# leaderboard sorting system in Godot. You can tweak it to handle more complex logic like optimizing the search algorithm or adjusting the array sizes.


==========================================================================


and then could you translate both of those into C+ for Unreal Engine 5?
ChatGPT said:
ChatGPT

Certainly! Translating both the leaderboard sorting and searching algorithm into C++ for Unreal Engine 5 will involve adjusting the syntax and structure to fit Unreal's framework. Unreal Engine uses its own classes and structures, but the core logic will be similar.

1. Leaderboard Sorting Example in C++ for Unreal Engine 5

We will use Unreal’s containers like TArray, and implement sorting and searching within a UObject or AActor class in Unreal.

C++ Version (Unreal Engine 5)

cpp
#pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "LeaderboardActor.generated.h" // Struct to hold player data USTRUCT(BlueprintType) struct FPlayerData { GENERATED_BODY() UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Player") int32 PlayerID; UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Player") int32 Score; FPlayerData() : PlayerID(0), Score(0) {} FPlayerData(int32 InPlayerID, int32 InScore) : PlayerID(InPlayerID), Score(InScore) {} }; UCLASS() class MYPROJECT_API ALeaderboardActor : public AActor { GENERATED_BODY() public: ALeaderboardActor(); protected: virtual void BeginPlay() override; // Array of arrays to simulate the leaderboard TArray<TArray<TArray<TArray<TArray<FPlayerData>>>>> Leaderboard; public: virtual void Tick(float DeltaTime) override; void InitializeLeaderboard(); void SortLeaderboard(); int32 FindPlayerScore(int32 PlayerID); // Custom sorting function static bool SortByScore(const FPlayerData& A, const FPlayerData& B); };

Implementation

cpp
#include "LeaderboardActor.h" ALeaderboardActor::ALeaderboardActor() { PrimaryActorTick.bCanEverTick = true; } void ALeaderboardActor::BeginPlay() { Super::BeginPlay(); InitializeLeaderboard(); SortLeaderboard(); int32 PlayerScore = FindPlayerScore(12345); UE_LOG(LogTemp, Warning, TEXT("Player 12345 score: %d"), PlayerScore); } void ALeaderboardActor::Tick(float DeltaTime) { Super::Tick(DeltaTime); } void ALeaderboardActor::InitializeLeaderboard() { Leaderboard.Reserve(10); for (int32 i = 0; i < 10; i++) { TArray<TArray<TArray<TArray<FPlayerData>>>> TensOfThousands; TensOfThousands.Reserve(10); for (int32 j = 0; j < 10; j++) { TArray<TArray<TArray<FPlayerData>>> Thousands; Thousands.Reserve(10); for (int32 k = 0; k < 10; k++) { TArray<TArray<FPlayerData>> Hundreds; Hundreds.Reserve(10); for (int32 l = 0; l < 10; l++) { TArray<FPlayerData> Tens; Tens.Reserve(10); for (int32 m = 0; m < 10; m++) { Tens.Add(FPlayerData(m + (l * 10) + (k * 100) + (j * 1000) + (i * 10000), FMath::RandRange(0, 100))); } Hundreds.Add(Tens); } Thousands.Add(Hundreds); } TensOfThousands.Add(Thousands); } Leaderboard.Add(TensOfThousands); } } void ALeaderboardActor::SortLeaderboard() { for (auto& TensOfThousands : Leaderboard) { for (auto& Thousands : TensOfThousands) { for (auto& Hundreds : Thousands) { for (auto& Tens : Hundreds) { Tens.Sort(ALeaderboardActor::SortByScore); } } } } } bool ALeaderboardActor::SortByScore(const FPlayerData& A, const FPlayerData& B) { return A.Score < B.Score; } int32 ALeaderboardActor::FindPlayerScore(int32 PlayerID) { for (const auto& TensOfThousands : Leaderboard) { for (const auto& Thousands : TensOfThousands) { for (const auto& Hundreds : Thousands) { for (const auto& Tens : Hundreds) { for (const FPlayerData& Player : Tens) { if (Player.PlayerID == PlayerID) { return Player.Score; } } } } } } return -1; // Player not found }

2. Key Unreal Engine Concepts Applied

  • Arrays: We use TArray in Unreal Engine, which is similar to GDScript's and C#’s arrays but tailored to Unreal’s memory management.

  • Sorting: Unreal uses the Sort() function on TArray, allowing us to sort the arrays with a custom comparator function (SortByScore).

  • Searching: The search is conducted using a nested loop structure to find a specific player’s score. This can be optimized for larger data sets by using more sophisticated search algorithms.

Notes:

  • The translation keeps the hierarchical leaderboard structure, and we use the Unreal Engine's logging system (UE_LOG) to print results during gameplay.
  • This C++ code integrates seamlessly with Unreal Engine’s actor-based system, making it suitable for use in an actual project.

This C++ version provides the same functionality as the GDScript and C# versions, adapted to Unreal Engine's structure. It allows you to create a nested leaderboard system and implement sorting and searching efficiently using Unreal's powerful C++ API.

No comments:

Post a Comment

too long for a dm.

 See new posts I asked Grok to take the cutting edge launguages they use for ai and sciece etc and build a piexel game engine in an html fil...