Tripredacus Posted February 14 Posted February 14 I started working on a project recently to do something I couldn't do for free. Basically a way to create a schedule for a league with constraints. I got past that part pretty easily and I am nearly satisfied with the result with two exceptions: 1. I want to be able to show the times the "player" appears in the first part of the sequence so that I can see how balanced the appearances are. 2. I want to be able to force the program to adhere to appearance constraints, where a "player" would appear in the first or second spot of a value either 4 or 5 times. Since this is using a situation where there is an odd number of Rounds, it may well be impossible for it to actually generate a schedule with the constraints I have placed upon the program. That would be fine. My primary issue is that I lost a version where I did have the appearance counting working. So here is the working code that generates 9 rounds of 12 player matchups. If we are to consider the output as being (Home, Away) then because I am using the random include, there are instances where a player is Home or away more than 5 times. expandcollapse popup#include <Array.au3> #include <_ArrayRandom.au3> Local $players[12] $players[0] = "A1" $players[1] = "A2" $players[2] = "A3" $players[3] = "A4" $players[4] = "A5" $players[5] = "A6" $players[6] = "B1" $players[7] = "B2" $players[8] = "B3" $players[9] = "B4" $players[10] = "B5" $players[11] = "B6" Local $n = UBound($players) Local $rounds[9][Int($n / 2)][2] ; Array for 9 rounds ; Constraints: Pairs that cannot both be first in any round Local $constraints[6][2] = [ _ ["A1", "A3"], _ ["A2", "A4"], _ ["A5", "B1"], _ ["A6", "B2"], _ ["B3", "B5"], _ ["B4", "B6"] _ ] For $r = 0 To 8 ; Loop for 9 rounds Local $validRound = False Local $attempts = 0 While Not $validRound And $attempts < 10000 ; Increase attempts to 10000 $attempts += 1 ; Shuffle players array instead of just shifting _ArrayRandom($players) For $i = 0 To Int($n / 2) - 1 $rounds[$r][$i][0] = $players[$i] $rounds[$r][$i][1] = $players[$n - 1 - $i] Next ; Check if the current pairing violates any constraint $validRound = True For $i = 0 To UBound($constraints) - 1 Local $count = 0 For $j = 0 To UBound($rounds, 2) - 1 If $rounds[$r][$j][0] = $constraints[$i][0] Or $rounds[$r][$j][0] = $constraints[$i][1] Then $count += 1 EndIf Next If $count > 1 Then ; If both elements of constraint are first in a pair $validRound = False ExitLoop EndIf Next If $validRound Then ExitLoop ; Exit if we have found a valid round EndIf Wend If Not $validRound Then ConsoleWrite("Failed to generate a valid round " & $r + 1 & " after 10000 attempts." & @CRLF) EndIf Next ; Display the rounds if needed For $r = 0 To UBound($rounds) - 1 ConsoleWrite("Round " & $r + 1 & ": ") For $i = 0 To UBound($rounds, 2) - 1 ConsoleWrite("(" & $rounds[$r][$i][0] & ", " & $rounds[$r][$i][1] & ") ") Next ConsoleWrite(@CRLF) Next Now yesterday I had set upon Grok to see how well it could handle AutoIT, and it did actually create code that displayed the player placement count. However, I've lost that instance and to make matter worse, Grok is not able to reproduce that work from yesterday. Whatever it tries to make now will always output NULLs, or invald info. And unfortunately I do not have the expertise on how to fix that problem, which was the entire reason why I pasted code onto Grok and Gemini yesterday. From yesterday I have the work that the LLMs tried to do to add the following: 1. To restrict first place in the pairing appearances to 5 2. To show the round counting (which did work at some point) Console outputs Nulls to the Rounds, and 0 to the player count in this version. expandcollapse popup#include <Array.au3> #include <_ArrayRandom.au3> Local $players[12] $players[0] = "A1" $players[1] = "A2" $players[2] = "A3" $players[3] = "A4" $players[4] = "A5" $players[5] = "A6" $players[6] = "B1" $players[7] = "B2" $players[8] = "B3" $players[9] = "B4" $players[10] = "B5" $players[11] = "B6" Local $n = UBound($players) Local $rounds[9][Int($n / 2)][2] ; Array for 9 rounds ; Initialize the $rounds array For $r = 0 To 8 For $i = 0 To Int($n / 2) - 1 $rounds[$r][$i][0] = "" ; Initialize to empty string $rounds[$r][$i][1] = "" ; Initialize to empty string Next Next ; Constraints: Pairs that cannot both be first in any round Local $constraints[6][2] = [ _ ["A1", "A3"], _ ["A2", "A4"], _ ["A5", "B1"], _ ["A6", "B2"], _ ["B3", "B5"], _ ["B4", "B6"] _ ] ; Array to track how many times each player has been in the first position Local $firstCount[$n] = [0,0,0,0,0,0,0,0,0,0,0,0] ; Function to find a valid pair for a player considering constraints and balance Func FindValidPair($player, $tempPlayers, $constraints, $firstCount) Local $validPairs[1] = [""] ; Initialize with one empty element For $i = 0 To UBound($tempPlayers) - 1 If $tempPlayers[$i] <> $player Then Local $valid = True For $j = 0 To UBound($constraints) - 1 If ($player = $constraints[$j][0] And $tempPlayers[$i] = $constraints[$j][1]) Or ($player = $constraints[$j][1] And $tempPlayers[$i] = $constraints[$j][0]) Then $valid = False ExitLoop EndIf Next If $valid Then ; Check balance Local $playerIndex = _ArraySearch($players, $player) Local $pairIndex = _ArraySearch($players, $tempPlayers[$i]) If ($firstCount[$playerIndex] < 5 And $firstCount[$pairIndex] < 5) Or ($firstCount[$playerIndex] > 4 And $firstCount[$pairIndex] > 4) Then _ArrayAdd($validPairs, $tempPlayers[$i]) EndIf EndIf EndIf Next If UBound($validPairs) > 1 Then ; Check if more than initial empty element Return $validPairs[Random(1, UBound($validPairs) - 1, 1)] ; Return a random valid pair, excluding the first empty element Else Return "" EndIf EndFunc For $r = 0 To 8 ; Loop for 9 rounds Local $validRound = False Local $attempts = 0 While Not $validRound And $attempts < 10000 ; Increase attempts to 10000 $attempts += 1 ; Shuffle players array Local $tempPlayers = $players _ArrayRandom($tempPlayers) ; Attempt to build this round Local $usedPlayers[1] = [""] ; Initialize with one empty element Local $roundFirstPlayers[1] = [""] ; Array to track first players in *successful* pairs For $i = 0 To Int($n / 2) - 1 Local $firstPlayer = "" For $p = 0 To UBound($tempPlayers) - 1 If Not _ArraySearch($usedPlayers, $tempPlayers[$p]) Then $firstPlayer = $tempPlayers[$p] ExitLoop EndIf Next If $firstPlayer = "" Then ExitLoop ; No more players to use as first Local $secondPlayer = FindValidPair($firstPlayer, $tempPlayers, $constraints, $firstCount) If $secondPlayer = "" Then ExitLoop ; Cant find valid pair, restart round EndIf $rounds[$r][$i][0] = $firstPlayer $rounds[$r][$i][1] = $secondPlayer _ArrayAdd($usedPlayers, $firstPlayer) _ArrayAdd($usedPlayers, $secondPlayer) _ArrayAdd($roundFirstPlayers, $firstPlayer) ; Add to the successful first players ; Update counts Local $firstIndex = _ArraySearch($players, $firstPlayer) $firstCount[$firstIndex] += 1 Next If UBound($usedPlayers) = $n + 1 Then ; All players used, including the initial empty element $validRound = True Else ; Reset count for this round if invalid ; Only reset counts for *successful* first players For $i = 0 To UBound($roundFirstPlayers) - 1 Local $index = _ArraySearch($players, $roundFirstPlayers[$i]) If $index <> -1 Then $firstCount[$index] -= 1 EndIf Next EndIf Wend If Not $validRound Then ConsoleWrite("Failed to generate a valid round " & $r + 1 & " after 10000 attempts." & @CRLF) EndIf Next ; Display the rounds if needed (This will now show empty strings if a pair isnt found) For $r = 0 To UBound($rounds) - 1 ConsoleWrite("Round " & $r + 1 & ": ") For $i = 0 To UBound($rounds, 2) - 1 ConsoleWrite("(" & $rounds[$r][$i][0] & ", " & $rounds[$r][$i][1] & ") ") Next ConsoleWrite(@CRLF) Next ; Display how many times each player was first for debugging For $i = 0 To $n - 1 ConsoleWrite($players[$i] & ": " & $firstCount[$i] & @CRLF) Next And this other version from today that DOES output valid rounds but the player counts are either a 9 or a 0. expandcollapse popup#include <Array.au3> #include <_ArrayRandom.au3> Local $players[12] $players[0] = "A1" $players[1] = "A2" $players[2] = "A3" $players[3] = "A4" $players[4] = "A5" $players[5] = "A6" $players[6] = "B1" $players[7] = "B2" $players[8] = "B3" $players[9] = "B4" $players[10] = "B5" $players[11] = "B6" Local $n = UBound($players) Local $rounds[9][Int($n / 2)][2] ; Array for 9 rounds ; Constraints: Pairs that cannot both be first in any round Local $constraints[6][2] = [ _ ["A1", "A3"], _ ["A2", "A4"], _ ["A5", "B1"], _ ["A6", "B2"], _ ["B3", "B5"], _ ["B4", "B6"] _ ] ; Array to track how many times each player has been in the first position Local $firstCounts[$n] = [0,0,0,0,0,0,0,0,0,0,0,0] For $r = 0 To 8 ; Loop for 9 rounds Local $validRound = False Local $attempts = 0 While Not $validRound And $attempts < 10000 ; Increase attempts to 10000 $attempts += 1 ; Shuffle players array instead of just shifting _ArrayRandom($players) For $i = 0 To Int($n / 2) - 1 $rounds[$r][$i][0] = $players[$i] $rounds[$r][$i][1] = $players[$n - 1 - $i] Next ; Check if the current pairing violates any constraint $validRound = True For $i = 0 To UBound($constraints) - 1 Local $count = 0 For $j = 0 To UBound($rounds, 2) - 1 If $rounds[$r][$j][0] = $constraints[$i][0] Or $rounds[$r][$j][0] = $constraints[$i][1] Then $count += 1 EndIf Next If $count > 1 Then ; If both elements of constraint are first in a pair $validRound = False ExitLoop EndIf Next If $validRound Then ; Count occurrences of each player as first For $i = 0 To UBound($rounds, 2) - 1 Local $player = $rounds[$r][$i][0] Local $playerIndex = _ArraySearch($players, $player) If $playerIndex <> -1 Then $firstCounts[$playerIndex] += 1 ; Debug output to check count update ConsoleWrite("Round " & $r + 1 & ": Incrementing " & $player & " to " & $firstCounts[$playerIndex] & @CRLF) Else ConsoleWrite("ERROR: Player " & $player & " not found in players array." & @CRLF) EndIf Next ; Immediate display to check counts after each round ConsoleWrite("After Round " & $r + 1 & @CRLF) For $i = 0 To $n - 1 ConsoleWrite($players[$i] & ": " & $firstCounts[$i] & @CRLF) Next ExitLoop ; Exit if weve found a valid round EndIf Wend If Not $validRound Then ConsoleWrite("Failed to generate a valid round " & $r + 1 & " after 10000 attempts." & @CRLF) EndIf Next ; Display the rounds if needed For $r = 0 To UBound($rounds) - 1 ConsoleWrite("Round " & $r + 1 & ": ") For $i = 0 To UBound($rounds, 2) - 1 ConsoleWrite("(" & $rounds[$r][$i][0] & ", " & $rounds[$r][$i][1] & ") ") Next ConsoleWrite(@CRLF) Next ; Display how many times each player was first ConsoleWrite(@CRLF & "Player First Counts:" & @CRLF) For $i = 0 To $n - 1 ConsoleWrite($players[$i] & ": " & $firstCounts[$i] & @CRLF) Next So this post is for two purposes: 1. Can a real person instead of a chatbot help me resolve either the counting or balance issue? 2. Both Grok and Gemini have similar issues when dealing with arrays, are they making some common mistake? Do these (or other) LLMs make these kinds of mistakes with other programming or scripting languages? Twitter | MSFN | VGCollect
Nine Posted February 14 Posted February 14 (edited) So basically you ask a human to solve a machine issue asked by another human. Instead of having this other human solves his own issue. I do not think I will help you for now on (ever). Edited February 14 by Nine Musashi 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Tripredacus Posted February 19 Author Posted February 19 You could have thought of it as a logical experiment. I figured out the answer later. Basically the error that the LLM makes is that it tries to do the counting at the wrong time. I was already able to create the array and the LLM wanted to try to do the counting during the creation of the array. Rather, it is solved by doing the counting after the array had all of the data in it. Twitter | MSFN | VGCollect
lIlIIlIllIIIIlI Posted February 20 Posted February 20 If you're gonna use ai for making programs, use chatgpt, grok is kind of bad and gemini is not as good. there are some other things that might be better like deepseek but you can use it for only like 10 prompts before their servers are overwhelmed and you have to wait hours. Chatgpt keeps your history so you can never "lose" a solution that it spits out for you.
rudi Posted February 27 Posted February 27 (edited) And in addition to the suggestion for ChatGPT: Break down your project into small steps, when using ChatGPT. e.g. I need a array <your description of sturcture and purpose> Then go on task by task. That way you get faaaar better results, than if you try to describe the whole story in one. Edited February 27 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now