View Single Post
Old 05-02-2023, 09:29 PM   #148 (permalink)
Xist
Not Doug
 
Xist's Avatar
 
Join Date: Jun 2012
Location: Show Low, AZ
Posts: 12,240

Chorizo - '00 Honda Civic HX, baby! :D
90 day: 35.35 mpg (US)

Mid-Life Crisis Fighter - '99 Honda Accord LX
90 day: 34.2 mpg (US)

Gramps - '04 Toyota Camry LE
90 day: 35.39 mpg (US)

Don't hit me bro - '05 Toyota Camry LE
90 day: 30.49 mpg (US)
Thanks: 7,254
Thanked 2,233 Times in 1,723 Posts
This is the first script that ChatGPT wrote me:
Code:
TWXProxy is a tool that allows you to run multiple instances of Trade Wars 2002, a classic online multiplayer game, on a single computer. With TWXProxy, you can connect to different game servers, automate your gameplay with scripts, and share your data with other players.
Here is a possible script for TWXProxy:
// This script will log in to a game server, create a new character, and start exploring the galaxy.
// Set the name of the character to create
setVar $characterName “TWXProxy”
// Set the password of the character to create
setVar $characterPassword “123456”
// Set the name of the game server to connect to
setVar $gameServer “tw2002.net”
// Set the port of the game server to connect to
setVar $gamePort “23”
// Connect to the game server
connect $gameServer $gamePort
// Wait for the login prompt
waitFor “Šontinue” send “C”
// Wait for the character selection prompt
waitFor “Enter your name” send $characterName & “*”
// Check if the character already exists
setTextLineTrigger characterExists :characterExists “That handle already exists in this game.”
setTextLineTrigger characterNew :characterNew “Do you wish this to be your new handle (Y/N)?” pause
:characterExists // The character already exists, so enter the password
killAllTriggers
waitFor “Enter your password”
send $characterPassword & “*”
goto :startGame
:characterNew // The character does not exist, so create a new one
killAllTriggers
send “Y*”
// Wait for the password prompt
waitFor “Enter a password for your new account”
send $characterPassword & “*”
// Wait for the gender prompt
waitFor “(M)ale or (F)emale?” send “M*”
// Wait for the race prompt
waitFor “(F)ederation, Žomulan, (K)lingon,” send “F*”
:startGame // The character is ready to start the game
// Wait for the game selection prompt
waitFor “(1) Federation War Zone” send “1*”
// Wait for the ship selection prompt
waitFor “(1) Scout Marauder” send “1*”
// Wait for the main menu prompt
waitFor “<T> Takeoff” send “T*”
// Start exploring the galaxy
// Set a variable to store the current sector number
setVar $currentSector 1
:exploreLoop // Loop through all sectors and scan them
// Scan the current sector send “SDSH*”
// Wait for the scan results
setTextLineTrigger densityScan :densityScan “Relative Density Scan” setTextLineTrigger holoScan :holoScan “<Re-Display>” pause
:densityScan // Parse the density scan results and store them in an array killAllTriggers
getWord CURRENTLINE $sector 4
setArray $densityScan 10
setTextLineTrigger density1 :density1 “[1]” setTextLineTrigger density2 :density2 “[2]” setTextLineTrigger density3 :density3 “[3]” setTextLineTrigger density4 :density4 “[4]” setTextLineTrigger density5 :density5 “[5]” setTextLineTrigger density6 :density6 “[6]” setTextLineTrigger density7 :density7 “[7]” setTextLineTrigger density8 :density8 “[8]” setTextLineTrigger density9 :density9 “[9]” setTextLineTrigger density10 :density10 “[10]” pause
:density1 killAllTriggers getWord CURRENTLINE $densityScan[1] 3 goto :densityScan
:density2 killAllTriggers getWord CURRENTLINE $densityScan[2] 3 goto :densityScan
:density3 killAllTriggers getWord CURRENTLINE $densityScan[3] 3 goto :densityScan
:density4 killAllTriggers getWord CURRENTLINE $densityScan[4] 3 goto :densityScan
:density5 killAllTriggers getWord CURRENTLINE $densityScan[5] 3 goto :densityScan
:density6 killAllTriggers getWord CURRENTLINE $densityScan[6] 3 goto :densityScan
:density7 killAllTriggers getWord CURRENTLINE $densityScan[7] 3 goto :densityScan
:density8 killAllTriggers getWord CURRENTLINE $densityScan[8] 3 goto :densityScan
:density9
As I have mentioned, much of this seems to be written for a different game.
I accidentally got it to write this:
Code:
# This script will get the distance of every sector in the game
# and store it in an array called $distance

# Set the array size to the number of sectors
getSectorParameter 1 "SECTOR.WARPCOUNT" $numSectors
setArray $distance $numSectors

# Loop through all the sectors
setVar $i 1
while ($i <= $numSectors)
  # Get the distance of the current sector from stardock
  getDistance $dist 1 $i
  # Store the distance in the array
  setVar $distance[$i] $dist
  # Increment the loop counter
  add $i 1
end

# Display the results
echo "**The distance of every sector from stardock is: **"
setVar $j 1
while ($j <= $numSectors)
  echo "*Sector " $j ": " $distance[$j] "*"
  add $j 1
end
I asked it to write a script get the distance of every sector in the game, it insisted it couldn't, and refused to talk about it again--until I accidentally asked again.

Code:
getSectorParameter 1 "SECTOR.WARPCOUNT" $numSectors
looks like it gets the number of sectors adjacent to sector 1, which are your adjacent sectors if you are in sector 1, and you often start there, but not necessarily.
Also, you don't use quotation marks there.
Sector 1 always has 6 warps out, so it creates an array with 6 spots.
I was actually looking at this when I was last trying to write my script:
Quote:
getDistance

Purpose: Internally calculates the distance between two sectors through the use of the TWX Proxy Database.

Syntax: getDistance var {fromSector} {toSector}
So, it gets the distance from sector 1 to sector 1, which may be the current sector.
Then it gets the distances from sector 1 to sectors 2-7, which are always adjacent, so it would get 0,1,1,1,1,1,1
Would you believe that to get the distance from sector 1 to StarDock you would write
Code:
getDistance $dist 1 STARDOCK?
I didn't realize you don't write the {}, I put them in my script!
To find the distances from every sector the the current sector I would write
Code:
getDistance $dist CURRENTSECTOR $1
If you are just going to display the distances to the screen, why not do that during the first loop?

I wanted to figure out how to do that, but someone on Discord pointed out that I don't need to go through every sector in the galaxy (sectors 11-20,000 in this case) to see which one is the closest, I do a breadth-first search to check adjacent sectors for what I want and then work my way out.

This is a program I found in C++ (having specified BASIC):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAX 5

struct Vertex {
   char label;
   bool visited;
};

//queue variables

int queue[MAX];
int rear = -1;
int front = 0;
int queueItemCount = 0;

//graph variables

//array of vertices
struct Vertex* lstVertices[MAX];

//adjacency matrix
int adjMatrix[MAX][MAX];

//vertex count
int vertexCount = 0;

//queue functions

void insert(int data) {
   queue[++rear] = data;
   queueItemCount++;
}

int removeData() {
   queueItemCount--;
   return queue[front++]; 
}

bool isQueueEmpty() {
   return queueItemCount == 0;
}

//graph functions

//add vertex to the vertex list
void addVertex(char label) {
   struct Vertex* vertex = (struct Vertex*) malloc(sizeof(struct Vertex));
   vertex->label = label;  
   vertex->visited = false;     
   lstVertices[vertexCount++] = vertex;
}

//add edge to edge array
void addEdge(int start,int end) {
   adjMatrix[start][end] = 1;
   adjMatrix[end][start] = 1;
}

//display the vertex
void displayVertex(int vertexIndex) {
   printf("%c ",lstVertices[vertexIndex]->label);
}       

//get the adjacent unvisited vertex
int getAdjUnvisitedVertex(int vertexIndex) {
   int i;
	
   for(i = 0; i<vertexCount; i++) {
      if(adjMatrix[vertexIndex][i] == 1 && lstVertices[i]->visited == false)
         return i;
   }
	
   return -1;
}

void breadthFirstSearch() {
   int i;

   //mark first node as visited
   lstVertices[0]->visited = true;

   //display the vertex
   displayVertex(0);   

   //insert vertex index in queue
   insert(0);
   int unvisitedVertex;

   while(!isQueueEmpty()) {
      //get the unvisited vertex of vertex which is at front of the queue
      int tempVertex = removeData();   

      //no adjacent vertex found
      while((unvisitedVertex = getAdjUnvisitedVertex(tempVertex)) != -1) {    
         lstVertices[unvisitedVertex]->visited = true;
         displayVertex(unvisitedVertex);
         insert(unvisitedVertex);               
      }
		
   }   

   //queue is empty, search is complete, reset the visited flag        
   for(i = 0;i<vertexCount;i++) {
      lstVertices[i]->visited = false;
   }    
}

int main() {
   int i, j;

   for(i = 0; i<MAX; i++) { // set adjacency 
      for(j = 0; j<MAX; j++) // matrix to 0
         adjMatrix[i][j] = 0;
   }

   addVertex('S');   // 0
   addVertex('A');   // 1
   addVertex('B');   // 2
   addVertex('C');   // 3
   addVertex('D');   // 4
 
   addEdge(0, 1);    // S - A
   addEdge(0, 2);    // S - B
   addEdge(0, 3);    // S - C
   addEdge(1, 4);    // A - D
   addEdge(2, 4);    // B - D
   addEdge(3, 4);    // C - D
	
   printf("\nBreadth First Search: ");
   
   breadthFirstSearch();

   return 0;
}
So, ChatGPT has written me two short scripts that were both horribly wrong.

Perhaps a breadth-first search script would have been more trouble than it is worth.

C++ is supposed to be one of the easiest languages to learn, but Python is even easier, although I don't understand the beginning of the sample script I found.
__________________
"Oh if you use math, reason, and logic you will be hated."--OilPan4

Last edited by Xist; 05-02-2023 at 09:34 PM..
  Reply With Quote