Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
|
|
|
|
Poster | Thread | OneTimer1
|  |
AI code generation for simple games on Amiga (or others) Posted on 18-Sep-2023 17:55:16
| | [ #1 ] |
| |
 |
Cult Member  |
Joined: 3-Aug-2015 Posts: 804
From: Unknown | | |
|
| Chapter 1
I was curious what ChatGPT could do for game programming on an Amiga.
To be honest, it couldn't do much at least not enough for something with GFX or SFX so I didn't dare to ask for something Amiga specific.
Finally I asked ChatGPT for an Adventure Code written in C running on a standard console, first I got this: Quote:
#include #include #include
// Define the structure of a room typedef struct room { char *name; // The name of the room char *description; // The description of the room struct room *north; // The pointer to the room to the north struct room *south; // The pointer to the room to the south struct room *east; // The pointer to the room to the east struct room *west; // The pointer to the room to the west } room;
// Define the structure of an object typedef struct object { char *name; // The name of the object char *description; // The description of the object int movable; // A flag indicating if the object can be moved struct object *next; // The pointer to the next object in the same room } object;
// Define a global variable for the current room room *current_room;
// Define a global variable for the inventory of objects object *inventory;
// Create a function that prints the current location and the objects in it void look() { printf("You are in %s.\n", current_room->name); printf("%s\n", current_room->description); object *obj = current_room->next; if (obj != NULL) { printf("You see:\n"); while (obj != NULL) { printf("- %s: %s\n", obj->name, obj->description); obj = obj->next; } } }
// Create a function that moves to a different room based on the direction void move(char *direction) { if (strcmp(direction, "north") == 0) { if (current_room->north != NULL) { current_room = current_room->north; look(); } else { printf("You cannot go north from here.\n"); } } else if (strcmp(direction, "south") == 0) { if (current_room->south != NULL) { current_room = current_room->south; look(); } else { printf("You cannot go south from here.\n"); } } else if (strcmp(direction, "east") == 0) { if (current_room->east != NULL) { current_room = current_room->east; look(); } else { printf("You cannot go east from here.\n"); } } else if (strcmp(direction, "west") == 0) { if (current_room->west != NULL) { current_room = current_room->west; look(); } else { printf("You cannot go west from here.\n"); } } else { printf("Invalid direction.\n"); } }
// Create a function that takes an object from the current room and adds it to the inventory void take(char *object_name) { object *obj = current_room->next; object *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, object_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("There is no such object here.\n"); } else if (obj->movable == 0) { printf("You cannot take that.\n"); } else { printf("You take %s.\n", obj->name); // Remove the object from the current room if (prev == NULL) { current_room->next = obj->next; } else { prev->next = obj->next; } // Add the object to the inventory obj->next = inventory; inventory = obj; } }
// Create a function that drops an object from the inventory and adds it to the current room void drop(char *object_name) { object *obj = inventory; object *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, object_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("You do not have such an object.\n"); } else { printf("You drop %s.\n", obj->name); // Remove the object from the inventory if (prev == NULL) { inventory = obj->next; } else { prev->next = obj->next; } // Add the object to the current room obj->next = current_room->next; current_room->next = obj; } }
// Create a function that prints the inventory of objects void inventory() { if (inventory == NULL) { printf("You have nothing.\n"); } else { printf("You have:\n"); object *obj = inventory; while (obj != NULL) { printf("- %s: %s\n", obj->name, obj->description); obj = obj->next; } } }
// Create a function that parses the user input and executes the corresponding command void parse(char *input) { char *command = strtok(input, " "); char *argument = strtok(NULL, " "); if (strcmp(command, "look") == 0) { look(); } else if (strcmp(command, "move") == 0) { if (argument == NULL) { printf("Move where?\n"); } else { move(argument); } } else if (strcmp(command, "take") == 0) { if (argument == NULL) { printf("Take what?\n"); } else { take(argument); } } else if (strcmp(command, "drop") == 0) { if (argument == NULL) { printf("Drop what?\n"); } else { drop(argument); } } else if (strcmp(command, "inventory") == 0) { inventory(); } else if (strcmp(command, "quit") == 0) { printf("Goodbye!\n"); exit(0); } else { printf("Unknown command.\n"); } }
// Create a function that initializes the rooms and objects void init() { // Create the rooms room *hallway = malloc(sizeof(room)); room *kitchen = malloc(sizeof(room)); room *living_room = malloc(sizeof(room)); room *bedroom = malloc(sizeof(room)); room *bathroom = malloc(sizeof(room));
// Set the names of the rooms hallway->name = "the hallway"; kitchen->name = "the kitchen"; living_room->name = "the living room"; bedroom->name = "the bedroom"; bathroom->name = "the bathroom";
// Set the descriptions of the rooms hallway->description = "A long and narrow corridor with doors on both sides."; kitchen->description = "A small and cozy kitchen with a fridge, a stove and a sink."; living_room->description = "A spacious and comfortable living room with a sofa, a TV and a fireplace."; bedroom->description = "A dark and quiet bedroom with a bed, a closet and a window."; bathroom->description = "A clean and bright bathroom with a toilet, a shower and a mirror.";
// Set the connections between the rooms hallway->north = kitchen; hallway->south = living_room; hallway->east = bedroom; hallway->west = bathroom; kitchen->north = NULL; kitchen->south = hallway; kitchen->east = NULL; kitchen->west = NULL;
living_room->north = hallway; living_room->south = NULL; living_room->east = NULL; living_room->west = NULL;
bedroom->north = NULL; bedroom->south = NULL; bedroom->east = NULL; bedroom->west = hallway;
bathroom->north = NULL; bathroom->south = NULL; bathroom->east = hallway; bathroom->west = NULL;
// Create the objects object *key = malloc(sizeof(object)); object *apple = malloc(sizeof(object)); object *remote = malloc(sizeof(object)); object *book = malloc(sizeof(object)); object *towel = malloc(sizeof(object));
// Set the names of the objects key->name = "key"; apple->name = "apple"; remote->name = "remote"; book->name = "book"; towel->name = "towel";
// Set the descriptions of the objects key->description = "A shiny silver key that might open something."; apple->description = "A red and juicy apple that looks delicious."; remote->description = "A black remote control that can turn on the TV."; book->description = "A thick book with a blue cover and a title that says 'The C Programming Language'."; towel->description = "A soft and fluffy towel that can dry you off.";
// Set the movability of the objects key->movable = 1; apple->movable = 1; remote->movable = 1; book->movable = 1; towel->movable = 1;
// Set the next pointers of the objects to NULL key->next = NULL; apple->next = NULL; remote->next = NULL; book->next = NULL; towel->next = NULL;
// Place the objects in the rooms kitchen->next = key; key->next = apple; living_room->next = remote;
bedroom->next = book;
bathroom->next = towel;
// Set the initial room and inventory current_room = hallway; inventory = NULL; }
// Create a function that prints the welcome message and the instructions void welcome() { printf("Welcome to the text adventure game!\n"); printf("You are in a small apartment with five rooms: a hallway, a kitchen, a living room, a bedroom and a bathroom.\n"); printf("You can explore the rooms and interact with the objects by typing commands.\n"); printf("The commands are:\n"); printf("- look: to look around and see what is in the room.\n"); printf("- move : to move to another room. The directions are north, south, east and west.\n"); printf("- take : to take an object from the room and add it to your inventory.\n"); printf("- drop : to drop an object from your inventory and leave it in the room.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); }
// Create a function that starts the game loop void start() { char input[100]; // Initialize the rooms and objects init();
// Print the welcome message and instructions welcome();
// Print the initial location and objects look();
// Start the game loop while (1) { printf("\nWhat do you want to do?\n"); fgets(input, 100, stdin); input[strcspn(input, "\n")] = 0; // Remove the newline character parse(input); } }
// The main function that runs the game int main() { start(); return 0; }
|
I looked impressive first, but to my disappointment it didn't compile without an error.
ChaGPT forgot a line of code in the room struct, If you want to compile it you can change the struct:
Quote:
typedef struct room { char *name; // The name of the room char *description; // The description of the room struct room *north; // The pointer to the room to the north struct room *south; // The pointer to the room to the south struct room *east; // The pointer to the room to the east struct room *west; // The pointer to the room to the west struct object *next; // The pointer to an object in the room } room;
|
Last edited by OneTimer1 on 18-Sep-2023 at 09:15 PM. Last edited by OneTimer1 on 18-Sep-2023 at 05:57 PM.
|
| Status: Offline |
| | OneTimer1
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 18-Sep-2023 18:07:38
| | [ #2 ] |
| |
 |
Cult Member  |
Joined: 3-Aug-2015 Posts: 804
From: Unknown | | |
|
| Chapter 2
I was interested more in a fantasy setting so I asked ChatGPT to create something in a medieval setting, and I asked the AI to correct the errors it made with the missing pointer in the room structure.
It responded with another program, it had the same structure and I did some minor editing and it can be compiled with every standard C-Compiler.
Quote:
#include #include #include #include
// Define the structure of a location typedef struct location { char *name; // The name of the location char *description; // The description of the location struct location *north; // The pointer to the location to the north struct location *south; // The pointer to the location to the south struct location *east; // The pointer to the location to the east struct location *west; // The pointer to the location to the west struct item *items; // The pointer to the first item in this location } location;
// Define the structure of an item typedef struct item { char *name; // The name of the item char *description; // The description of the item int movable; // A flag indicating if the item can be moved struct item *next; // The pointer to the next item in the same location } item;
// Define a global variable for the current location location *current_location;
// Define a global variable for the inventory of items item *inventory;
// Create a function that prints the current position and the items in it void look(bool detail) { printf("You are in %s.\n", current_location->name); printf("%s\n", current_location->description); item *obj = current_location->items; // Get the first item in this location if (obj != NULL) { printf("You see:\n"); while (obj != NULL) { // Loop until there are no more items printf("- %s: %s\n", obj->name, obj->description); // Print the name and description of this item obj = obj->next; // Get the next item in this location } } if (detail) printf("You can move to:\n"); // Print the possible directions else printf("Possible directions:\n"); // Print the possible directions
if (current_location->north != NULL) { // Check if there is a location to the north if (detail) printf("- north: %s\n", current_location->north->name); // Print the name of the location to the north else printf(" north"); } if (current_location->south != NULL) { // Check if there is a location to the south if (detail) printf("- south: %s\n", current_location->south->name); // Print the name of the location to the south else printf(" south"); } if (current_location->east != NULL) { // Check if there is a location to the east if (detail) printf("- east: %s\n", current_location->east->name); // Print the name of the location to the east else printf(" east"); } if (current_location->west != NULL) { // Check if there is a location to the west if (detail) printf("- west: %s\n", current_location->west->name); // Print the name of the location to the west else printf(" west"); } }
// Create a function that moves to a different location based on the direction void move(char *direction) { if (strcmp(direction, "north") == 0) { if (current_location->north != NULL) { current_location = current_location->north; look(false); } else { printf("You cannot go north from here.\n"); } } else if (strcmp(direction, "south") == 0) { if (current_location->south != NULL) { current_location = current_location->south; look(false); } else { printf("You cannot go south from here.\n"); } } else if (strcmp(direction, "east") == 0) { if (current_location->east != NULL) { current_location = current_location->east; look(false); } else { printf("You cannot go east from here.\n"); } } else if (strcmp(direction, "west") == 0) { if (current_location->west != NULL) { current_location = current_location->west; look(false); } else { printf("You cannot go west from here.\n"); } } else { printf("Invalid direction.\n"); } }
// Create a function that takes an item from the current location and adds it to the inventory void take(char *item_name) { item *obj = current_location->items; item *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, item_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("There is no such item here.\n"); } else if (obj->movable == 0) { printf("You cannot take that.\n"); } else { printf("You take %s.\n", obj->name); // Remove the item from the current location if (prev == NULL) { current_location->items = obj->next; } else { prev->next = obj->next; } // Add the item to the inventory obj->next = inventory; inventory = obj; } }
// Create a function that drops an item from the inventory and adds it to the current location void drop(char *item_name) { item *obj = inventory; item *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, item_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("You do not have such an item.\n"); } else { printf("You drop %s.\n", obj->name); // Remove the item from the inventory if (prev == NULL) { inventory = obj->next; } else { prev->next = obj->next; } // Add the item to the current location obj->next = current_location->items; current_location->items = obj; } }
// Create a function that prints the inventory of items void inventory_fkt() { if (inventory == NULL) { printf("You have nothing.\n"); } else { printf("You have:\n"); item *obj = inventory; while (obj != NULL) { printf("- %s: %s\n", obj->name, obj->description); obj = obj->next; } } }
void print_help() { printf("The commands are:\n"); printf("- look: to look around and see what is in the location.\n"); printf("- move : to move to another location. The directions are north, south, east and west.\n"); printf("- take : to take an item from the location and add it to your inventory.\n"); printf("- drop : to drop an item from your inventory and leave it in the location.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); } // Create a function that parses the user input and executes the corresponding command void parse(char *input) { char *command = strtok(input, " "); char *argument = strtok(NULL, " "); if (strcmp(command, "look") == 0) { look(true); } else if (strcmp(command, "move") == 0) { if (argument == NULL) { printf("Move where?\n"); } else { move(argument); } } else if (strcmp(command, "go") == 0) { if (argument == NULL) { printf("Go where?\n"); } else { move(argument); } } else if (strcmp(command, "take") == 0) { if (argument == NULL) { printf("Take what?\n"); } else { take(argument); } } else if (strcmp(command, "get") == 0) { if (argument == NULL) { printf("Get what?\n"); } else { take(argument); } } else if (strcmp(command, "drop") == 0) { if (argument == NULL) { printf("Drop what?\n"); } else { drop(argument); } } else if (strcmp(command, "help") == 0) { print_help(); } else if (strcmp(command, "inventory") == 0) { inventory_fkt(); } else if (strcmp(command, "quit") == 0) { printf("Goodbye!\n"); exit(0); } else { printf("Unknown command.\n"); } }
// Create a function that initializes the locations and items void init() { // Create the locations location *castle = malloc(sizeof(location)); location *forest = malloc(sizeof(location)); location *village = malloc(sizeof(location)); location *cave = malloc(sizeof(location)); location *tower = malloc(sizeof(location)); location *bridge = malloc(sizeof(location)); location *lake = malloc(sizeof(location)); location *island = malloc(sizeof(location));
// Set the names of the locations castle->name = "the castle"; forest->name = "the forest"; village->name = "the village"; cave->name = "the cave"; tower->name = "the tower"; bridge->name = "the bridge"; lake->name = "the lake"; island->name = "the island";
// Set the descriptions of the locations castle->description = "A majestic and fortified castle with high walls and towers."; forest->description = "A dense and dark forest with tall trees and wild animals."; village->description = "A peaceful and friendly village with houses and shops."; cave->description = "A damp and gloomy cave with stalactites and stalagmites."; tower->description = "A tall and mysterious tower with a spiral staircase and a locked door."; bridge->description = "A wooden and rickety bridge that crosses a deep ravine."; lake->description = "A large and clear lake that reflects the sky and the mountains."; island->description = "A small and secluded island with a hut and a palm tree.";
// Set the connections between the locations castle->north = forest; castle->south = village; castle->east = tower; castle->west = cave; forest->north = NULL; forest->south = castle; forest->east = bridge; forest->east = bridge; forest->west = NULL;
village->north = castle; village->south = NULL; village->east = NULL; village->west = NULL;
cave->north = NULL; cave->south = NULL; cave->east = castle; cave->west = NULL;
tower->north = NULL; tower->south = NULL; tower->east = NULL; tower->west = castle;
bridge->north = NULL; bridge->south = NULL; bridge->east = lake; bridge->west = forest;
lake->north = NULL; lake->south = NULL; lake->east = island; lake->west = bridge;
island->north = NULL; island->south = NULL; island->east = NULL; island->west = lake;
// Create the items item *sword = malloc(sizeof(item)); item *shield = malloc(sizeof(item)); item *bow = malloc(sizeof(item)); item *arrow = malloc(sizeof(item)); item *key = malloc(sizeof(item)); item *apple = malloc(sizeof(item)); item *coin = malloc(sizeof(item)); item *map = malloc(sizeof(item)); item *torch = malloc(sizeof(item)); item *fish = malloc(sizeof(item));
// Set the names of the items sword->name = "sword"; shield->name = "shield"; bow->name = "bow"; arrow->name = "arrow"; key->name = "key"; apple->name = "apple"; coin->name = "coin"; map->name = "map"; torch->name = "torch"; fish->name = "fish";
// Set the descriptions of the items sword->description = "A sharp and sturdy sword that can cut through anything."; shield->description = "A round and heavy shield that can block any attack."; bow->description = "A long and flexible bow that can shoot arrows far and fast."; arrow->description = "A pointed and feathered arrow that can pierce through anything."; key->description = "A rusty and old key that might open something."; apple->description = "A red and juicy apple that looks delicious."; coin->description = "A shiny gold coin that can buy something."; map->description = "A worn and torn map that shows the layout of the land."; torch->description = "A wooden and lit torch that can illuminate the dark."; fish->description = "A fresh and tasty fish that can be eaten.";
// Set the movability of the items sword->movable = 1; shield->movable = 1; bow->movable = 1; arrow->movable = 1; key->movable = 1; apple->movable = 1; coin->movable = 1; map->movable = 1; torch->movable = 1; fish->movable = 1;
// Set the next pointers of the items to NULL sword->next = NULL; shield->next = NULL; bow->next = NULL; arrow->next = NULL; key->next = NULL; apple->next = NULL; coin->next = NULL; map->next = NULL; torch->next = NULL; fish->next = NULL;
// Place the items in the locations castle->items = sword; // Assign the items pointer of castle to point to sword sword->next = shield; // Link sword to shield
forest->items = bow; // Assign the items pointer of forest to point to bow bow->next = arrow; // Link bow to arrow
village->items = coin; // Assign the items pointer of village to point to coin
cave->items = key; // Assign the items pointer of cave to point to key
tower->items = map; // Assign the items pointer of tower to point to map
bridge->items = NULL; // Assign the items pointer of bridge to NULL, since there are no items here
lake->items = fish; // Assign the items pointer of lake to point to fish
island->items = apple; // Assign the items pointer of island to point to apple
// Set the initial location and inventory current_location = castle; inventory = NULL; }
// Create a function that prints the welcome message and the instructions void welcome() { printf("Welcome to the text adventure game!\n"); printf("You are in a medieval fantasy world with eight locations: a castle, a forest, a village, a cave, a tower, a bridge, a lake and an island.\n"); printf("You can explore the locations and interact with the items by typing commands.\n"); printf("The commands are:\n"); printf("- look: to look around and see what is in the location.\n"); printf("- move : to move to another location. The directions are north, south, east and west.\n"); printf("- take : to take an item from the location and add it to your inventory.\n"); printf("- drop : to drop an item from your inventory and leave it in the location.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); }
// Create a function that starts the game loop void start() { char input[100]; // Initialize the locations and items init();
// Print the welcome message and instructions welcome();
// Print the initial position and items look(false);
// Start the game loop while (1) { printf("\nWhat do you want to do?\n"); fgets(input, 100, stdin); input[strcspn(input, "\n")] = 0; // Remove the newline character parse(input); } }
// The main function that runs the game int main() { // Start the game start(); // Return 0 to indicate successful termination return 0; }
|
Last edited by OneTimer1 on 18-Sep-2023 at 09:15 PM. Last edited by OneTimer1 on 18-Sep-2023 at 09:14 PM.
|
| Status: Offline |
| | OneTimer1
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 18-Sep-2023 18:18:19
| | [ #3 ] |
| |
 |
Cult Member  |
Joined: 3-Aug-2015 Posts: 804
From: Unknown | | |
|
| Chapter 3
I went a bit further an changed the parser so it will accept very short singe character command, back in the days when I was playing text adventures, most of the game didn't consist of fight with dragon, evil sorcerers or black knight your main enemy was the parser. Some text parser could understood long and complicated English texts and that was exactly the part that fascinated me at most, I tried it in German but I failed, my mother tongue is much more challenging in grammar therefor writing a powerful parser will be a mess.
But the P&C Adventures from Lucas Art told me I was on a wrong way, even the best parser will frustrate gamers, you can try and use simple commands out of a very short list, so playing would be faster.
So I changed this ChatGPT adventure for a faster parser:
Quote:
#include #include #include #include
// Define the structure of a location typedef struct location { char *name; // The name of the location char *description; // The description of the location struct location *north; // The pointer to the location to the north struct location *south; // The pointer to the location to the south struct location *east; // The pointer to the location to the east struct location *west; // The pointer to the location to the west struct item *items; // The pointer to the first item in this location } location;
// Define the structure of an item typedef struct item { char *name; // The name of the item char *description; // The description of the item int movable; // A flag indicating if the item can be moved struct item *next; // The pointer to the next item in the same location } item;
// Define a global variable for the current location location *current_location;
// Define a global variable for the inventory of items item *inventory;
// Create a function that prints the current position and the items in it void look(bool detail) { printf("You are in %s.\n", current_location->name); printf("%s\n", current_location->description); item *obj = current_location->items; // Get the first item in this location if (obj != NULL) { printf("You see:\n"); while (obj != NULL) { // Loop until there are no more items printf("- %s: %s\n", obj->name, obj->description); // Print the name and description of this item obj = obj->next; // Get the next item in this location } } if (detail) printf("You can move to:\n"); // Print the possible directions else printf("Possible directions:\n"); // Print the possible directions
if (current_location->north != NULL) { // Check if there is a location to the north if (detail) printf("- north: %s\n", current_location->north->name); // Print the name of the location to the north else printf(" north"); } if (current_location->south != NULL) { // Check if there is a location to the south if (detail) printf("- south: %s\n", current_location->south->name); // Print the name of the location to the south else printf(" south"); } if (current_location->east != NULL) { // Check if there is a location to the east if (detail) printf("- east: %s\n", current_location->east->name); // Print the name of the location to the east else printf(" east"); } if (current_location->west != NULL) { // Check if there is a location to the west if (detail) printf("- west: %s\n", current_location->west->name); // Print the name of the location to the west else printf(" west"); } }
// Create a function that moves to a different location based on the direction void move(char *direction) { if (strcmp(direction, "north") == 0) { if (current_location->north != NULL) { current_location = current_location->north; look(false); } else { printf("You cannot go north from here.\n"); } } else if (strcmp(direction, "south") == 0) { if (current_location->south != NULL) { current_location = current_location->south; look(false); } else { printf("You cannot go south from here.\n"); } } else if (strcmp(direction, "east") == 0) { if (current_location->east != NULL) { current_location = current_location->east; look(false); } else { printf("You cannot go east from here.\n"); } } else if (strcmp(direction, "west") == 0) { if (current_location->west != NULL) { current_location = current_location->west; look(false); } else { printf("You cannot go west from here.\n"); } } else { printf("Invalid direction.\n"); } }
// Create a function that takes an item from the current location and adds it to the inventory void take(char *item_name) { item *obj = current_location->items; item *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, item_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("There is no such item here.\n"); } else if (obj->movable == 0) { printf("You cannot take that.\n"); } else { printf("You take %s.\n", obj->name); // Remove the item from the current location if (prev == NULL) { current_location->items = obj->next; } else { prev->next = obj->next; } // Add the item to the inventory obj->next = inventory; inventory = obj; } }
// Create a function that drops an item from the inventory and adds it to the current location void drop(char *item_name) { item *obj = inventory; item *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, item_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("You do not have such an item.\n"); } else { printf("You drop %s.\n", obj->name); // Remove the item from the inventory if (prev == NULL) { inventory = obj->next; } else { prev->next = obj->next; } // Add the item to the current location obj->next = current_location->items; current_location->items = obj; } }
// Create a function that prints the inventory of items void inventory_fkt() { if (inventory == NULL) { printf("You have nothing.\n"); } else { printf("You have:\n"); item *obj = inventory; while (obj != NULL) { printf("- %s: %s\n", obj->name, obj->description); obj = obj->next; } } }
void print_help() { printf("The commands are:\n"); printf("- look: to look around and see what is in the location.\n"); printf("- go/move : to move to another location. The directions are north, south, east and west.\n"); printf("- get/take : to take an item from the location and add it to your inventory.\n"); printf("- drop : to drop an item from your inventory and leave it in the location.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); printf("If you want to move faster, try:\n"); printf(" n: move north, s: move south, w: move west, e: move east\n"); printf("And we also understand other short commands:\n"); printf(" l: look, g/t: take, d: drop, i: inventory\n"); }
// Create a function that parses the user input and executes the corresponding command void parse(char *input) { char *command = strtok(input, " "); char *argument = strtok(NULL, " "); if ((strcmp(command, "look") == 0) || (strcmp(command, "l") == 0)) { look(true); } else if (strcmp(command, "move") == 0) { if (argument == NULL) { printf("Move where?\n"); } else { move(argument); } } else if (strcmp(command, "go") == 0) { if (argument == NULL) { printf("Go where?\n"); } else { move(argument); } } else if (strcmp(command, "n") == 0) { move("north"); } else if (strcmp(command, "s") == 0) { move("south"); } else if (strcmp(command, "w") == 0) { move("west"); } else if (strcmp(command, "e") == 0) { move("east"); } else if ((strcmp(command, "take") == 0) || (strcmp(command, "t") == 0)) { if (argument == NULL) { printf("Take what?\n"); } else { take(argument); } } else if ((strcmp(command, "get") == 0) || (strcmp(command, "g") == 0)) { if (argument == NULL) { printf("Get what?\n"); } else { take(argument); } } else if ((strcmp(command, "drop") == 0) || (strcmp(command, "d") == 0)) { if (argument == NULL) { printf("Drop what?\n"); } else { drop(argument); } } else if ((strcmp(command, "help") == 0) || (strcmp(command, "h") == 0)) { print_help(); } else if ((strcmp(command, "inventory") == 0) || (strcmp(command, "i") == 0)) { inventory_fkt(); } else if (strcmp(command, "quit") == 0) { printf("Goodbye!\n"); exit(0); } else { printf("Unknown command.\n"); } }
// Create a function that initializes the locations and items void init() { // Create the locations location *castle = malloc(sizeof(location)); location *forest = malloc(sizeof(location)); location *village = malloc(sizeof(location)); location *cave = malloc(sizeof(location)); location *tower = malloc(sizeof(location)); location *bridge = malloc(sizeof(location)); location *lake = malloc(sizeof(location)); location *island = malloc(sizeof(location));
// Set the names of the locations castle->name = "the castle"; forest->name = "the forest"; village->name = "the village"; cave->name = "the cave"; tower->name = "the tower"; bridge->name = "the bridge"; lake->name = "the lake"; island->name = "the island";
// Set the descriptions of the locations castle->description = "A majestic and fortified castle with high walls and towers."; forest->description = "A dense and dark forest with tall trees and wild animals."; village->description = "A peaceful and friendly village with houses and shops."; cave->description = "A damp and gloomy cave with stalactites and stalagmites."; tower->description = "A tall and mysterious tower with a spiral staircase and a locked door."; bridge->description = "A wooden and rickety bridge that crosses a deep ravine."; lake->description = "A large and clear lake that reflects the sky and the mountains."; island->description = "A small and secluded island with a hut and a palm tree.";
// Set the connections between the locations castle->north = forest; castle->south = village; castle->east = tower; castle->west = cave; forest->north = NULL; forest->south = castle; forest->east = bridge; forest->east = bridge; forest->west = NULL;
village->north = castle; village->south = NULL; village->east = NULL; village->west = NULL;
cave->north = NULL; cave->south = NULL; cave->east = castle; cave->west = NULL;
tower->north = NULL; tower->south = NULL; tower->east = NULL; tower->west = castle;
bridge->north = NULL; bridge->south = NULL; bridge->east = lake; bridge->west = forest;
lake->north = NULL; lake->south = NULL; lake->east = island; lake->west = bridge;
island->north = NULL; island->south = NULL; island->east = NULL; island->west = lake;
// Create the items item *sword = malloc(sizeof(item)); item *shield = malloc(sizeof(item)); item *bow = malloc(sizeof(item)); item *arrow = malloc(sizeof(item)); item *key = malloc(sizeof(item)); item *apple = malloc(sizeof(item)); item *coin = malloc(sizeof(item)); item *map = malloc(sizeof(item)); item *torch = malloc(sizeof(item)); item *fish = malloc(sizeof(item));
// Set the names of the items sword->name = "sword"; shield->name = "shield"; bow->name = "bow"; arrow->name = "arrow"; key->name = "key"; apple->name = "apple"; coin->name = "coin"; map->name = "map"; torch->name = "torch"; fish->name = "fish";
// Set the descriptions of the items sword->description = "A sharp and sturdy sword that can cut through anything."; shield->description = "A round and heavy shield that can block any attack."; bow->description = "A long and flexible bow that can shoot arrows far and fast."; arrow->description = "A pointed and feathered arrow that can pierce through anything."; key->description = "A rusty and old key that might open something."; apple->description = "A red and juicy apple that looks delicious."; coin->description = "A shiny gold coin that can buy something."; map->description = "A worn and torn map that shows the layout of the land."; torch->description = "A wooden and lit torch that can illuminate the dark."; fish->description = "A fresh and tasty fish that can be eaten.";
// Set the movability of the items sword->movable = 1; shield->movable = 1; bow->movable = 1; arrow->movable = 1; key->movable = 1; apple->movable = 1; coin->movable = 1; map->movable = 1; torch->movable = 1; fish->movable = 1;
// Set the next pointers of the items to NULL sword->next = NULL; shield->next = NULL; bow->next = NULL; arrow->next = NULL; key->next = NULL; apple->next = NULL; coin->next = NULL; map->next = NULL; torch->next = NULL; fish->next = NULL;
// Place the items in the locations castle->items = sword; // Assign the items pointer of castle to point to sword sword->next = shield; // Link sword to shield
forest->items = bow; // Assign the items pointer of forest to point to bow bow->next = arrow; // Link bow to arrow
village->items = coin; // Assign the items pointer of village to point to coin
cave->items = key; // Assign the items pointer of cave to point to key
tower->items = map; // Assign the items pointer of tower to point to map
bridge->items = NULL; // Assign the items pointer of bridge to NULL, since there are no items here
lake->items = fish; // Assign the items pointer of lake to point to fish
island->items = apple; // Assign the items pointer of island to point to apple
// Set the initial location and inventory current_location = castle; inventory = NULL; }
// Create a function that prints the welcome message and the instructions void welcome() { printf("Welcome to the text adventure game!\n"); printf("You are in a medieval fantasy world with eight locations: a castle, a forest, a village, a cave, a tower, a bridge, a lake and an island.\n"); printf("You can explore the locations and interact with the items by typing commands.\n"); printf("The commands are:\n"); printf("- look: to look around and see what is in the location.\n"); printf("- move : to move to another location. The directions are north, south, east and west.\n"); printf("- take : to take an item from the location and add it to your inventory.\n"); printf("- drop : to drop an item from your inventory and leave it in the location.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); }
// Create a function that starts the game loop void start() { char input[100]; // Initialize the locations and items init();
// Print the welcome message and instructions welcome();
// Print the initial position and items look(false);
// Start the game loop while (1) { printf("\nWhat do you want to do?\n"); fgets(input, 100, stdin); input[strcspn(input, "\n")] = 0; // Remove the newline character parse(input); } }
// The main function that runs the game int main() { // Start the game start(); // Return 0 to indicate successful termination return 0; }
|
Last edited by OneTimer1 on 18-Sep-2023 at 09:16 PM.
|
| Status: Offline |
| | OneTimer1
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 18-Sep-2023 18:29:00
| | [ #4 ] |
| |
 |
Cult Member  |
Joined: 3-Aug-2015 Posts: 804
From: Unknown | | |
|
| Chapter 4
Walking around and taking items doesn't seem enough to me, so I added another struct for NPC. The NPCs are there you can see them, but you can't do much with them. Quote:
#include #include #include #include
// Define the structure of a location typedef struct location { char *name; // The name of the location char *description; // The description of the location struct location *north; // The pointer to the location to the north struct location *south; // The pointer to the location to the south struct location *east; // The pointer to the location to the east struct location *west; // The pointer to the location to the west struct item *items; // The pointer to the first item in this location struct npc *npc; // The pointer to a non player character in this location } location;
// Define the structure of an item typedef struct item { char *name; // The name of the item char *description; // The description of the item int movable; // A flag indicating if the item can be moved struct item *next; // The pointer to the next item in the same location } item;
// Define the structure of an NPC typedef struct npc { char *name; // The name of the NPC char *description; // The description of the NPC struct npc *next; // The pointer to the next item in the same location } npc;
// Define a global variable for the current location location *current_location;
// Define a global variable for the inventory of items item *inventory;
// Create a function that prints the current position and the items in it void look(bool detail) { item *obj = current_location->items; // Get the first item in this location npc *creat = current_location->npc; // Get the first npc in this location printf("You are in %s.\n", current_location->name); printf("%s\n", current_location->description);
if (obj != NULL) { printf("You see:\n"); while (obj != NULL) { // Loop until there are no more items printf("- %s: %s\n", obj->name, obj->description); // Print the name and description of this item obj = obj->next; // Get the next item in this location } }
if (creat != NULL) { printf("You see:\n"); while (creat != NULL) { // Loop until there are no more items printf("- %s: %s\n", creat->name, creat->description); // Print the name and description of this item creat = creat->next; // Get the next item in this location } } if (detail) printf("You can move to:\n"); // Print the possible directions else printf("Possible directions:\n"); // Print the possible directions
if (current_location->north != NULL) { // Check if there is a location to the north if (detail) printf("- north: %s\n", current_location->north->name); // Print the name of the location to the north else printf(" north"); } if (current_location->south != NULL) { // Check if there is a location to the south if (detail) printf("- south: %s\n", current_location->south->name); // Print the name of the location to the south else printf(" south"); } if (current_location->east != NULL) { // Check if there is a location to the east if (detail) printf("- east: %s\n", current_location->east->name); // Print the name of the location to the east else printf(" east"); } if (current_location->west != NULL) { // Check if there is a location to the west if (detail) printf("- west: %s\n", current_location->west->name); // Print the name of the location to the west else printf(" west"); } }
// Create a function that moves to a different location based on the direction void move(char *direction) { if (strcmp(direction, "north") == 0) { if (current_location->north != NULL) { current_location = current_location->north; look(false); } else { printf("You cannot go north from here.\n"); } } else if (strcmp(direction, "south") == 0) { if (current_location->south != NULL) { current_location = current_location->south; look(false); } else { printf("You cannot go south from here.\n"); } } else if (strcmp(direction, "east") == 0) { if (current_location->east != NULL) { current_location = current_location->east; look(false); } else { printf("You cannot go east from here.\n"); } } else if (strcmp(direction, "west") == 0) { if (current_location->west != NULL) { current_location = current_location->west; look(false); } else { printf("You cannot go west from here.\n"); } } else { printf("Invalid direction.\n"); } }
// Create a function that takes an item from the current location and adds it to the inventory void take(char *item_name) { item *obj = current_location->items; item *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, item_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("There is no such item here.\n"); } else if (obj->movable == 0) { printf("You cannot take that.\n"); } else { printf("You take %s.\n", obj->name); // Remove the item from the current location if (prev == NULL) { current_location->items = obj->next; } else { prev->next = obj->next; } // Add the item to the inventory obj->next = inventory; inventory = obj; } }
// Create a function that drops an item from the inventory and adds it to the current location void drop(char *item_name) { item *obj = inventory; item *prev = NULL; while (obj != NULL) { if (strcmp(obj->name, item_name) == 0) { break; } prev = obj; obj = obj->next; } if (obj == NULL) { printf("You do not have such an item.\n"); } else { printf("You drop %s.\n", obj->name); // Remove the item from the inventory if (prev == NULL) { inventory = obj->next; } else { prev->next = obj->next; } // Add the item to the current location obj->next = current_location->items; current_location->items = obj; } }
// Create a function that prints the inventory of items void inventory_fkt() { if (inventory == NULL) { printf("You have nothing.\n"); } else { printf("You have:\n"); item *obj = inventory; while (obj != NULL) { printf("- %s: %s\n", obj->name, obj->description); obj = obj->next; } } }
void print_help() { printf("The commands are:\n"); printf("- look: to look around and see what is in the location.\n"); printf("- go/move : to move to another location. The directions are north, south, east and west.\n"); printf("- get/take : to take an item from the location and add it to your inventory.\n"); printf("- drop : to drop an item from your inventory and leave it in the location.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); printf("If you want to move faster, try:\n"); printf(" n: move north, s: move south, w: move west, e: move east\n"); printf("And we also understand other short commands:\n"); printf(" l: look, g/t: take, d: drop, i: inventory\n"); }
// Create a function that parses the user input and executes the corresponding command void parse(char *input) { char *command = strtok(input, " "); char *argument = strtok(NULL, " "); if ((strcmp(command, "look") == 0) || (strcmp(command, "l") == 0)) { look(true); } else if (strcmp(command, "move") == 0) { if (argument == NULL) { printf("Move where?\n"); } else { move(argument); } } else if (strcmp(command, "go") == 0) { if (argument == NULL) { printf("Go where?\n"); } else { move(argument); } } else if (strcmp(command, "n") == 0) { move("north"); } else if (strcmp(command, "s") == 0) { move("south"); } else if (strcmp(command, "w") == 0) { move("west"); } else if (strcmp(command, "e") == 0) { move("east"); } else if ((strcmp(command, "take") == 0) || (strcmp(command, "t") == 0)) { if (argument == NULL) { printf("Take what?\n"); } else { take(argument); } } else if ((strcmp(command, "get") == 0) || (strcmp(command, "g") == 0)) { if (argument == NULL) { printf("Get what?\n"); } else { take(argument); } } else if ((strcmp(command, "drop") == 0) || (strcmp(command, "d") == 0)) { if (argument == NULL) { printf("Drop what?\n"); } else { drop(argument); } } else if ((strcmp(command, "help") == 0) || (strcmp(command, "h") == 0)) { print_help(); } else if ((strcmp(command, "inventory") == 0) || (strcmp(command, "i") == 0)) { inventory_fkt(); } else if (strcmp(command, "quit") == 0) { printf("Goodbye!\n"); exit(0); } else { printf("Unknown command.\n"); } }
// Create a function that initializes the locations and items void init() { // ------------------------------------------------ // Locations // Create the locations location *castle = malloc(sizeof(location)); location *forest = malloc(sizeof(location)); location *village = malloc(sizeof(location)); location *cave = malloc(sizeof(location)); location *tower = malloc(sizeof(location)); location *bridge = malloc(sizeof(location)); location *lake = malloc(sizeof(location)); location *island = malloc(sizeof(location));
// Set the names of the locations castle->name = "the castle"; forest->name = "the forest"; village->name = "the village"; cave->name = "the cave"; tower->name = "the tower"; bridge->name = "the bridge"; lake->name = "the lake"; island->name = "the island";
// Set the descriptions of the locations castle->description = "A majestic and fortified castle with high walls and towers."; forest->description = "A dense and dark forest with tall trees and wild animals."; village->description = "A peaceful and friendly village with houses and shops."; cave->description = "A damp and gloomy cave with stalactites and stalagmites."; tower->description = "A tall and mysterious tower with a spiral staircase and a locked door."; bridge->description = "A wooden and rickety bridge that crosses a deep ravine."; lake->description = "A large and clear lake that reflects the sky and the mountains."; island->description = "A small and secluded island with a hut and a palm tree.";
// Set the connections between the locations castle->north = forest; castle->south = village; castle->east = tower; castle->west = cave; forest->north = NULL; forest->south = castle; forest->east = bridge; forest->east = bridge; forest->west = NULL;
village->north = castle; village->south = NULL; village->east = NULL; village->west = NULL;
cave->north = NULL; cave->south = NULL; cave->east = castle; cave->west = NULL;
tower->north = NULL; tower->south = NULL; tower->east = NULL; tower->west = castle;
bridge->north = NULL; bridge->south = NULL; bridge->east = lake; bridge->west = forest;
lake->north = NULL; lake->south = NULL; lake->east = island; lake->west = bridge;
island->north = NULL; island->south = NULL; island->east = NULL; island->west = lake;
// Set the initial location and inventory current_location = castle; inventory = NULL; // ------------------------------------------------ // Items // Create the items item *sword = malloc(sizeof(item)); item *shield = malloc(sizeof(item)); item *bow = malloc(sizeof(item)); item *arrow = malloc(sizeof(item)); item *key = malloc(sizeof(item)); item *apple = malloc(sizeof(item)); item *coin = malloc(sizeof(item)); item *map = malloc(sizeof(item)); item *torch = malloc(sizeof(item)); item *fish = malloc(sizeof(item));
// Set the names of the items sword->name = "sword"; shield->name = "shield"; bow->name = "bow"; arrow->name = "arrow"; key->name = "key"; apple->name = "apple"; coin->name = "coin"; map->name = "map"; torch->name = "torch"; fish->name = "fish";
// Set the descriptions of the items sword->description = "A sharp and sturdy sword that can cut through anything."; shield->description = "A round and heavy shield that can block any attack."; bow->description = "A long and flexible bow that can shoot arrows far and fast."; arrow->description = "A pointed and feathered arrow that can pierce through anything."; key->description = "A rusty and old key that might open something."; apple->description = "A red and juicy apple that looks delicious."; coin->description = "A shiny gold coin that can buy something."; map->description = "A worn and torn map that shows the layout of the land."; torch->description = "A wooden and lit torch that can illuminate the dark."; fish->description = "A fresh and tasty fish that can be eaten.";
// Set the movability of the items sword->movable = 1; shield->movable = 1; bow->movable = 1; arrow->movable = 1; key->movable = 1; apple->movable = 1; coin->movable = 1; map->movable = 1; torch->movable = 1; fish->movable = 1;
// Set the next pointers of the items to NULL sword->next = NULL; shield->next = NULL; bow->next = NULL; arrow->next = NULL; key->next = NULL; apple->next = NULL; coin->next = NULL; map->next = NULL; torch->next = NULL; fish->next = NULL;
// Place the items in the locations castle->items = sword; // Assign the items pointer of castle to point to sword sword->next = shield; // Link sword to shield
forest->items = bow; // Assign the items pointer of forest to point to bow bow->next = arrow; // Link bow to arrow
village->items = coin; // Assign the items pointer of village to point to coin
cave->items = key; // Assign the items pointer of cave to point to key
tower->items = map; // Assign the items pointer of tower to point to map
bridge->items = NULL; // Assign the items pointer of bridge to NULL, since there are no items here
lake->items = fish; // Assign the items pointer of lake to point to fish
island->items = apple; // Assign the items pointer of island to point to apple
// ------------------------------------------------ // NPCs // Create the NPCs npc npc *dragon = malloc(sizeof(npc)); npc *imp = malloc(sizeof(npc)); npc *fisher = malloc(sizeof(npc));
// Set the names of the NPCs dragon->name = "dragon"; imp->name = "imp"; fisher->name = "fisher";
// Set the descriptions of the items dragon->description = "A giant dragon, his eyes spreading pure terror."; imp->description = "An ugly looking green imp, looking like a crossbreed of a dwarf and a frog."; fisher->description = "A friendly looking fisher man, he seem to be wrong at this place.";
// Set the values of the NPCs # //
// Set the next pointers of the NPCs to NULL dragon->next = NULL; imp->next = NULL; fisher->next = NULL;
// Place the NPCs in the locations village->npc = fisher; // Assign the items pointer of castle to point to sword bridge->npc = imp; // Link sword to shield forest->npc = dragon; // Assign the items pointer of forest to point to bow }
// Create a function that prints the welcome message and the instructions void welcome() { printf("Welcome to the text adventure game!\n"); printf("You are in a medieval fantasy world with eight locations: a castle, a forest, a village, a cave, a tower, a bridge, a lake and an island.\n"); printf("You can explore the locations and interact with the items by typing commands.\n"); printf("The commands are:\n"); printf("- look: to look around and see what is in the location.\n"); printf("- move : to move to another location. The directions are north, south, east and west.\n"); printf("- take : to take an item from the location and add it to your inventory.\n"); printf("- drop : to drop an item from your inventory and leave it in the location.\n"); printf("- inventory: to see what you have in your inventory.\n"); printf("- quit: to quit the game.\n"); }
// Create a function that starts the game loop void start() { char input[100]; // Initialize the locations and items init();
// Print the welcome message and instructions welcome();
// Print the initial position and items look(false);
// Start the game loop while (1) { printf("\nWhat do you want to do?\n"); fgets(input, 100, stdin); input[strcspn(input, "\n")] = 0; // Remove the newline character parse(input); } }
// The main function that runs the game int main() { // Start the game start(); // Return 0 to indicate successful termination return 0; }
|
Normally I would have to implement actions that could be done with those NPCs:
- Talking with them - Attacking them - Buying things from them
But this means more, I can't just attack a mighty dragon with a fish, an Item needs a meaning, something like a flag for a weapon or hit points.
There are 2 different ways to go: The RPG way: Every Item has values like Hit Points, NPC has strength, health, could be friend or foe, could carry items, The main player has strength, health, ... If you have a main Item or defeated a boss NPC you win.
The Adventure way: You need a very narrow defined set of actions to win.
Last edited by OneTimer1 on 18-Sep-2023 at 09:18 PM. Last edited by OneTimer1 on 18-Sep-2023 at 09:17 PM. Last edited by OneTimer1 on 18-Sep-2023 at 09:16 PM. Last edited by OneTimer1 on 18-Sep-2023 at 09:16 PM.
|
| Status: Offline |
| | OneTimer1
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 19-Sep-2023 22:11:15
| | [ #5 ] |
| |
 |
Cult Member  |
Joined: 3-Aug-2015 Posts: 804
From: Unknown | | |
|
| Chapter 5
Executables
These demo games for Amiga are available here: adventure1 adventure2 adventure3 adventure4
The games where compiled using a cross compiler, it would be nice if I got some jḱind of feedback:
[_] Download working [_] Executable under AOS3.x [_] Executable under AOS1.3 [_] Crashing on my 68k Amiga.
Thank you for testing. Last edited by OneTimer1 on 20-Sep-2023 at 06:20 PM. Last edited by OneTimer1 on 20-Sep-2023 at 06:09 PM. Last edited by OneTimer1 on 19-Sep-2023 at 10:17 PM.
|
| Status: Offline |
| | Bugala
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 22-Sep-2023 17:28:17
| | [ #6 ] |
| |
 |
Cult Member  |
Joined: 21-Aug-2007 Posts: 649
From: Finland | | |
|
| @OneTimer1
Thanks, this was interesting read to see how text adventures should be done. Had took a dive to text adventures long long ago, but never had this sophisticated approach to the coding of them, and have always bit wondered about how should they have been done.
|
| Status: Offline |
| | wajdy
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 22-Sep-2023 21:55:11
| | [ #7 ] |
| |
 |
Regular Member  |
Joined: 27-Oct-2006 Posts: 191
From: Amigania | | |
|
| You forced it to code LOL.
Can you show us some pics ?
|
| Status: Offline |
| | NutsAboutAmiga
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 23-Sep-2023 14:41:15
| | [ #8 ] |
| |
 |
Elite Member  |
Joined: 9-Jun-2004 Posts: 12607
From: Norway | | |
|
| @OneTimer1
Executable under AOS4.1
Looks like you none terminated string bug, crashed just after, “you see:” followed by - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! string.
the 2en time tryed the game it started as it should.. and got the the prompt
pressing CTRL+C i get a crash again. but game did not exit... i ignored the crash, and typed QUIT to end the game.
In conclusion perhaps you did not initialize the pointers. perhaps you did not check if pointers are set.
Last edited by NutsAboutAmiga on 23-Sep-2023 at 02:51 PM. Last edited by NutsAboutAmiga on 23-Sep-2023 at 02:48 PM. Last edited by NutsAboutAmiga on 23-Sep-2023 at 02:46 PM. Last edited by NutsAboutAmiga on 23-Sep-2023 at 02:45 PM. Last edited by NutsAboutAmiga on 23-Sep-2023 at 02:42 PM.
_________________ http://lifeofliveforit.blogspot.no/ Facebook::LiveForIt Software for AmigaOS |
| Status: Offline |
| | NutsAboutAmiga
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 23-Sep-2023 14:54:26
| | [ #9 ] |
| |
 |
Elite Member  |
Joined: 9-Jun-2004 Posts: 12607
From: Norway | | |
|
| | Status: Offline |
| | NutsAboutAmiga
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 23-Sep-2023 15:11:04
| | [ #10 ] |
| |
 |
Elite Member  |
Joined: 9-Jun-2004 Posts: 12607
From: Norway | | |
|
| | Status: Offline |
| | OneTimer1
|  |
Re: AI code generation for simple games on Amiga (or others) Posted on 24-Sep-2023 17:53:05
| | [ #11 ] |
| |
 |
Cult Member  |
Joined: 3-Aug-2015 Posts: 804
From: Unknown | | |
|
| @NutsAboutAmiga
Quote:
what is this line???
char *argument = strtok(NULL, " ");
clearly this line is wrong.. its not supposed to be used like that..
|
True, it doesn't seem logic to me, ChatGPT wrote the 1st program, I only corrected errors that made compiling impossible and made some tiny enhancements. there is still an error in the 1st. program.
Version 2,3,4 where compiled under Linux using GCC and worked, there could be some differences, because memory or pointers might be set to '0' as default on some systems. A very nasty problem if you are doing X-platform development.
I think I will check it next time on an (emulated?) Amiga
ps.:
Look to thre example of strtok() here: https://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm
token = strtok(NULL, s); // get a pointer to the next token in the string it got before.
I never used this function before but it worked on Linux.Last edited by OneTimer1 on 24-Sep-2023 at 06:00 PM.
|
| Status: Offline |
| |
|
|
|
[ home ][ about us ][ privacy ]
[ forums ][ classifieds ]
[ links ][ news archive ]
[ link to us ][ user account ]
|