ChatGPT - MUD Game

Olga avatar
By Olga
at 2022-12-07T13:24

Table of Contents

用AI寫MUD不是夢,不過限制是4000字。
AI 也會 LPMud。

1.
// https://chat.openai.com/chat

// Me: please write a mud in c

// Sure, here's a simple example of a mud written in C:
// Copy code
#include <stdio.h>

/* Define constants for the game */
#define MAX_ROOMS 10
#define MAX_ITEMS 10

/* Define structs for rooms, items, and the player */
struct room {
char *description;
struct room *north;
struct room *south;
struct room *east;
struct room *west;
struct item *items;
};

struct item {
char *description;
struct item *next;
};

struct player {
struct room *location;
struct item *inventory;
};

/* Define some global variables for the game */
struct room rooms[MAX_ROOMS];
struct player player;

/* Function prototypes */
void create_rooms();
void init_game();
void print_location();
void print_inventory();
void go(char *direction);
void get_item(char *item_name);
void drop_item(char *item_name);

int main() {
char input[100];
char *command;
char *argument;

init_game();

while (1) {
printf("\n> ");
scanf("%[^\n]s", input);

/* Parse the input into a command and argument */
command = strtok(input, " ");
argument = strtok(NULL, " ");

if (strcmp(command, "go") == 0) {
go(argument);
} else if (strcmp(command, "get") == 0) {
get_item(argument);
} else if (strcmp(command, "drop") == 0) {
drop_item(argument);
} else if (strcmp(command, "location") == 0) {
print_location();
} else if (strcmp(command, "inventory") == 0) {
print_inventory();
} else if (strcmp(command, "quit") == 0) {
break;
} else {
printf("I don't understand that command.\n");
}
}

return 0;
}

/* Create all the rooms in the game */
void create_rooms() {
/* Room descriptions */
rooms[0].description = "You are in a dark cave.";
rooms[1].description = "You are in a bright forest.";
rooms[2].description = "You are in a cold ice cave.";
rooms[3].description = "You are on a grassy plain.";
rooms[4].description = "You are in a hot desert.";

/* Room connections */
rooms[0].north = &rooms[1];
rooms[1].south = &rooms[0];
rooms[1].west = &rooms[2];
rooms[2].east = &rooms[1];
rooms[2].north = &rooms[3];
rooms[3].south = &rooms[2];
rooms[3].west = &rooms[4];
rooms[4].east = &rooms[3];

/* Room items */
rooms[0].items = NULL;
rooms[1

// Me: show me the next page
// An error occurred. If this issue persists please contact us through
// our help center at help.openai.com.

// Me: and then?
// Too many requests, please slow down

2.
// Me: write a mud in c
// Here is an example of a simple text-based game written in C:

// Copy code
#include <stdio.h>
#include <string.h>

// Declare the main function
int main() {
// Print a welcome message
printf("Welcome to the MUD!\n");

// Set up the player's initial location
char location[20] = "town square";

// Set up a variable to store the player's input
char input[20];

// Set up a flag to indicate when the game should end
int end_game = 0;

// Run the game loop
while (end_game == 0) {
// Print the player's current location
printf("You are in the %s.\n", location);

// Print a prompt and get the player's input
printf("> ");
scanf("%s", input);

// Check the player's input and change the location accordingly
if (strcmp(input, "north") == 0) {
strcpy(location, "northern land");
} else if (strcmp(input, "south") == 0) {
strcpy(location, "southern land");
} else if (strcmp(input, "east") == 0) {
strcpy(location, "eastern land");
} else if (strcmp(input, "west") == 0) {
strcpy(location, "western land");
} else if (strcmp(input, "quit") == 0) {
// If the player entered "quit", end the game
end_game = 1;
} else {
// If the player entered something else, print an error message
printf("I don't understand what you mean.\n");
}
}

// Print a goodbye message
printf("Thanks for playing the MUD!\n");

return 0;
}
// This is just a simple example to illustrate how a text-based game
// could be written in C. It could be expanded upon and improved
// in many different ways, such as adding more locations, items,
// and features.

3.
// Ref: https://applealmond.com/posts/167138
// https://beta.openai.com/playground/p/default-chat

// write a MUD in C
// AI:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// world data structure

struct Room {
char* name;
int north;
int east;
int south;
int west;
struct Item *items;
};

struct Item {
char* name;
int canPickup;
};

struct Player {
int currentRoom;
struct Item *inventory;
};

// AI functions

void AI(struct Room *rooms, struct Player *player) {
// get current room and find an item in it
struct Room *currRoom = &rooms[player->currentRoom];
if (currRoom->items != NULL) {
struct Item *item = currRoom->items;
// pick up item if possible
if (item->canPickup == 1) {
// add item to player's inventory
player->inventory = item;
}
// else move to next room
else {
// pick random direction
int dir = rand() % 4;
if (dir == 0) {
// move north
player->currentRoom = currRoom->north;
}
else if (dir == 1) {
// move east
player->currentRoom = currRoom->east;
}
else if (dir == 2) {
// move south
player->currentRoom = currRoom->south;
}
else if (dir == 3) {
// move west
player->currentRoom = currRoom->west;
}
}
}
// else move to next room
else {
// pick random direction
int dir = rand() % 4;
if (dir == 0) {
// move north
player->currentRoom = currRoom->north;
}
else if (dir == 1) {
// move east
player->currentRoom = currRoom->east;
}
else if (dir == 2) {
// move south
player->currentRoom = currRoom->south;
}
else if (dir == 3) {
// move west
player->currentRoom = currRoom->west;
}
}
}

int main(int argc, char **argv) {
// initialize world
struct Room rooms[10];
rooms[0].name = "room1";
rooms[0].north = 0;
rooms[0].east = 2;
rooms[0].south = 3;
rooms[0].west = 0;
rooms[0].items = malloc(sizeof(struct Item));
rooms[0].items->name = "key";
rooms[0].items->canPickup = 1;
rooms[1].name = "room2";

// initialize player
struct Player player;
player.currentRoom = 0;
player.inventory = NULL;

// start AI loop
while (1) {
AI(rooms, &player);
}

return 0;
}

4.
Write a MUD in C with chinese text.
AI:

#include <stdio.h>
#include <string.h>

// Chinese text structure
typedef struct ChineseText {
char text[65];
} ChineseText;

// MUD map structure
typedef struct Map {
int width;
int height;
ChineseText text[20][20]; // 20x20 map
int enemies[20][20]; // number of enemies in a location
} Map;

// Player character structure
typedef struct Character {
int xPos, yPos; // Position on the map
int HP;
int att, def; // Attack and defense stats
} Character;

int main(int argc, char *argv[]) {
// Initialize the game
Map map;
Character player;

player.xPos = 0;
player.yPos = 0;
player.HP = 100;
player.att = 10;
player.def = 5;

// Load the map
for (int x = 0; x < 20; x++) {
for (int y = 0; y < 20; y++) {
strcpy(map.text[x][y].text, "此位置暂无内容");
// no content at this location
map.enemies[x][y] = 0; // no enemies at start
}
}

// Main game loop
while (player.HP > 0) {
// Print out a description of the current location
printf("你现在站在:%s\n",
map.text[player.xPos][player.yPos].text);
printf("附近有 %d 个敌人\n",
map.enemies[player.xPos][player.yPos]);

// Take user input
char input[32];
fgets(input, 32, stdin);

// Parse the user's input
if (strcmp(input, "前进") == 0) {
// Move the player position forward one spot
player.xPos++;
} else if (strcmp(input, "后退") == 0) {
// Move the player position backward one spot
player.xPos--;
} else if (strcmp(input, "攻击") == 0) {
// Attack the enemies at this location
if (map.enemies[player.xPos][player.yPos] > 0) {
// Calculate attack damage
int damage = player.att -
map.enemies[player.xPos][player.yPos] * 2;

// Subtract damage from enemies
map.enemies[player.xPos][player.yPos] -=
damage;

// Print out result of attack
printf("你对敌人造成了 %d 点伤害\n", damage);
}
}

// Check for game over conditions
if (player.xPos < 0 || player.xPos >= 20 || player.yPos < 0
|| player.yPos >= 20) {
printf("你被踩到了外太空!游戏结束!\n");
break;
}
}

return 0;
}
// Human:

5.
// write a MUD in C with chinese text and tab width 2

// AI:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 中文字符串需转换成Unicode编码
const char *WELCOME_MSG = "\x4f60\x597d\xff0c\x6b22\x8fce\x6765
\x5217\x83f2\x7684\x5192\x9669\xff01\n";

// 定义玩家结构体
typedef struct {
// 游戏中使用的各种变量
int hp;
int mp;
int xp;
int gold;
// 玩家当前所处地图
int map;
int x;
int y;
int dir;
} Player;

// 定义地图结构体
typedef struct {
int width;
int height;
char **map;
} Map;

// 全局变量,用于储存玩家信息
Player player;

// 初始化函数: 新建玩家,创建地图
void init() {
// 初始化玩家信息
player.hp = 100;
player.mp = 100;
player.xp = 0;
player.gold = 0;
player.map = 0;
player.x = 0;
player.y = 0;
player.dir = 0;

// 初始化地图
Map map;
map.width = 10;
map.height = 10;
map.map = malloc(map.width * map.height);
for (int i = 0; i < map.width; i++) {
for (int j = 0; j < map.height; j++) {
if (i == 0 || j == 0 ||
i == map.width-1 || j == map.height-1) {
map.map[i][j] = '#';
} else {
map.map[i][j] = '.';
}
}
}
}

// 用于显示地图的函数
void showMap() {
for (int i = 0; i < map.width; i++) {
for (int j = 0; j < map.height; j++) {
printf("%02x ", map.map[i][j]);
}
printf("\n");
}
}

// 接受玩家的指令,进行相应的处理
void processCommand(char *cmd) {
if (strcmp(cmd, "quit") == 0) {
printf("\x5173\x95ed\xff01\n");
exit(0);
}
}

int main() {
// 游戏开始,输出欢迎消息
printf(WELCOME_MSG);

// 初始化
init();

// 无限循环,接受并处理玩家指令
while (1) {
// 显示地图
showMap();

// 提示玩家输入
printf("\x8bf7\x8f93\x5165\x547d\x4ee4\xff1a");

// 读取玩家输入
char cmd[256] = {0};
scanf("%s", &cmd);

// 处理玩家输入
processCommand(cmd);
}

return 0;
}

6.
// Me: write a LPMud mob code.
// AI:
/* AI for Mob in a LPMud */

inherit "/std/living/ai";

void create()
{
::create();

// Set up default stats
set_str(10);
set_dex(10);
set_con(10);
set_int(10);
set_wis(10);
set_cha(10);

// Set up default attack and defense ratings
set_attack_level(1);
set_defense_level(1);

// Set up default movement speed
set_speed(2);

// Set up default aggression behavior
set_aggressive(FALSE);

// Set up the places where mob will move
set_move_after(600, "/room/path/to/mob/destination1");
set_move_after(1200, "/room/path/to/mob/destination2");
set_move_after(1800, "/room/path/to/mob/destination3");

// Set up a specific message that is displayed upon entering the room
set_enter_room_msg("The mob enters the room silently.");

// Set up response to being attacked
set_on_attack_response("The mob responds with aggressive hatred!\n");

// Set up response to being hit
set_on_hurt_response("The mob grunts in pain.\n");
}

7.
// Me: write MUD game save and load function in C

// function to save the MUD game
void SaveGame(FILE *fptr)
{
// Declare all necessary variables
int i;
Room** rooms = GetRooms();
int numRooms = GetNumRooms();
Character** characters = GetCharacters();
int numCharacters = GetNumCharacters();

// Save all rooms
for(i=0; i<numRooms; i++)
{
fprintf(fptr, "room:[%s][%d][%d]\n",
rooms[i]->name,
rooms[i]->x_location,
rooms[i]->y_location);
}

// Save all characters
for(i=0; i<numCharacters; i++)
{
fprintf(fptr, "character:[%s][%d][%d]\n",
characters[i]->name,
characters[i]->x_location,
characters[i]->y_location);
}
}

// function to load the MUD game

void LoadGame(FILE *fptr)
{
// Declare all necessary variables
char line[256];
char name[32];
int x_location;
int y_location;

while(fgets(line, sizeof(line), fptr))
{
// Parse the line of data
sscanf(line, "%*[^:]:[%[^]]][%d][%d]\n", name,
&x_location, &y_location);

if (strncmp(line, "room:", 5) == 0)
{
// Create a room object with the given parameters
CreateRoom(name, x_location, y_location);
}
else if (strncmp(line, "character:", 10) == 0)
{
// Create a character object with the given parameters
CreateCharacter(name, x_location, y_location);
}
}
}

--
Tags: 線上

All Comments

Noah avatar
By Noah
at 2022-12-10T13:49
真假?!
Heather avatar
By Heather
at 2022-12-13T14:14
Anthony avatar
By Anthony
at 2022-12-16T14:40
讚啦!!
Jacob avatar
By Jacob
at 2022-12-19T15:05
收入精華區z-3-20 :D
Brianna avatar
By Brianna
at 2022-12-22T15:31
XD
Agnes avatar
By Agnes
at 2022-12-25T15:56
為什麼我問他, 他說他不會寫XD
Irma avatar
By Irma
at 2022-12-28T16:21
我問他能不能用LPC串接OpenAI,他有丟範例給我XD
Catherine avatar
By Catherine
at 2022-12-31T16:47
太神

轉生系動畫怪物資料

Ingrid avatar
By Ingrid
at 2022-12-07T09:20
我沒看小說,所以資料全部從動畫找,動畫有提到名字的就用 動畫的名字(動畫瘋),沒提到的我先深度搜尋,再沒找到就自 己掰。預計參考以下怪物眾多(而且部份還雷同)的作品 *1.轉生史萊姆 2.轉生蜘蛛 3.月光下的異世界 *4.菜鳥鍊金術士 5.熊熊勇闖異世界 6.其它 參考目的: 大部份將做為朱拉大森林的怪 ...

第二賽季大量平衡更新

Odelette avatar
By Odelette
at 2022-12-07T03:56
量真的非常非常多 所以開發者敘述就不翻了等官方 輸出角色的被動不再獲得移動速度加成,換彈速度從 25 增加到 35% 毀滅拳王 火箭拳 衝擊傷害(打到人)從 15~30 增加到 25~50(此區間為依據集氣時間的最大最小傷害) 撞牆傷害從 20~40 減少到 10~30 強化火箭拳的暈眩時間從 0.5~1 ...

第二賽季戰鬥通行證造型

Lucy avatar
By Lucy
at 2022-12-07T03:27
更新完了 第二季開始! 另外因為平衡數據很多我另外發一篇 這邊主要放戰鬥通行證給的東西 https://i.imgur.com/Sp1KV9T.jpg 購買直接解鎖拉瑪塔 + 假面騎士76(名為蟲蟲英雄) https://i.imgur.com/xm88mIW.jpg https://i.imgur.c ...

5.12版本更新公告

Mason avatar
By Mason
at 2022-12-06T22:45
情報來源:https://is.gd/8Nt7Ow 這是今年最後一次的版本更新,版本期間也拉比較長(下一次更新是1月的6.0版本),來 看看5.12版本改了些什麼內容吧。 https://i.imgur.com/1sHKKI2.jpg 特務更新 超精彩的顛覆者冠軍賽結束後,職業賽 ...

最近台服的中國人多了好多

Ingrid avatar
By Ingrid
at 2022-12-06T22:26
不知是不是我的錯覺,感覺這幾天一直排到很多簡體字的玩家atat 台服和陸服應該是分開的吧,還是亞洲服大家都一起排,日韓的常常排到是沒錯,但我記得 中國伺服器不都特別弄一個的 還是中國那邊的鬥陣有出什麼事,所以他們流亡到台服這邊atat? - ...