Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

напиши простую 3д игру в консоли на C#

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with o3-2025-04-16’s answer.
  1. User

    напиши простую 3д игру в консоли на C#

  2. Assistant

    Создать полноценную 3D игру в консоли на C# — задача очень сложная из-за ограничений консоли (текстовый вывод, отсутствие графики и 3D-рендеринга). Но можно сделать простейшую имитацию 3D с помощью ASCII-графики и базовой логики.

    Ниже — пример простой "3D" игры-лабиринта в консоли на C#, где игрок может двигаться по коридорам, а стены отображаются с эффектом перспективы (raycasting-подобный подход, упрощённый).


    Пример: Минималистичный 3D-лабиринт (raycasting)

    using System;
    
    class Simple3DConsoleGame
    {
        static int mapWidth = 16;
        static int mapHeight = 16;
    
        static string[] map = new string[]
        {
            "################",
            "#..............#",
            "#.......########",
            "#..............#",
            "#......##......#",
            "#......##......#",
            "#..............#",
            "###............#",
            "##.............#",
            "#......####..###",
            "#......#.......#",
            "#......#.......#",
            "#..............#",
            "#......#########",
            "#..............#",
            "################"
        };
    
        static double playerX = 14.7;
        static double playerY = 5.09;
        static double playerAngle = 0.0;
    
        const double FOV = Math.PI / 4.0; // 45 градусов
        const double depth = 16.0;        // дальность видимости
    
        static int screenWidth = 120;
        static int screenHeight = 40;
    
        static void Main()
        {
            Console.SetWindowSize(screenWidth, screenHeight);
            Console.SetBufferSize(screenWidth, screenHeight);
            Console.CursorVisible = false;
    
            while (true)
            {
                DrawFrame();
                HandleInput();
            }
        }
    
        static void DrawFrame()
        {
            char[] screen = new char[screenWidth * screenHeight];
    
            for (int i = 0; i < screen.Length; i++)
                screen[i] = ' ';
    
            for (int x = 0; x < screenWidth; x++)
            {
                // Рассчитываем угол луча для текущей колонки
                double rayAngle = (playerAngle - FOV / 2.0) + ((double)x / screenWidth) * FOV;
    
                double distanceToWall = 0;
                bool hitWall = false;
                bool boundary = false;
    
                double eyeX = Math.Sin(rayAngle);
                double eyeY = Math.Cos(rayAngle);
    
                while (!hitWall && distanceToWall < depth)
                {
                    distanceToWall += 0.1;
    
                    int testX = (int)(playerX + eyeX * distanceToWall);
                    int testY = (int)(playerY + eyeY * distanceToWall);
    
                    // Проверка выхода за карту
                    if (testX < 0 || testX >= mapWidth || testY < 0 || testY >= mapHeight)
                    {
                        hitWall = true;
                        distanceToWall = depth;
                    }
                    else
                    {
                        if (map[testY][testX] == '#')
                        {
                            hitWall = true;
    
                            // Проверка границ для эффекта "контуров"
                            var boundaries = new System.Collections.Generic.List<double>();
    
                            for (int tx = 0; tx < 2; tx++)
                                for (int ty = 0; ty < 2; ty++)
                                {
                                    double vx = testX + tx - playerX;
                                    double vy = testY + ty - playerY;
                                    double d = Math.Sqrt(vx * vx + vy * vy);
                                    double dot = (eyeX * vx / d) + (eyeY * vy / d);
                                    boundaries.Add(d * (1 - dot));
                                }
    
                            boundaries.Sort();
                            if (boundaries[0] < 0.01)
                                boundary = true;
                        }
                    }
                }
    
                // Расчет высоты стены на экране
                int ceiling = (int)((screenHeight / 2.0) - screenHeight / distanceToWall);
                int floor = screenHeight - ceiling;
    
                char wallShade;
    
                if (distanceToWall <= depth / 4.0)       wallShade = '\u2588'; // Очень близко
                else if (distanceToWall < depth / 3.0)   wallShade = '\u2593';
                else if (distanceToWall < depth / 2.0)   wallShade = '\u2592';
                else if (distanceToWall < depth)         wallShade = '\u2591';
                else                                     wallShade = ' ';
    
                if (boundary) wallShade = ' '; // Граница стен — пусто
    
                for (int y = 0; y < screenHeight; y++)
                {
                    if (y < ceiling)
                        screen[y * screenWidth + x] = ' ';
                    else if (y > ceiling && y <= floor)
                        screen[y * screenWidth + x] = wallShade;
                    else
                    {
                        // Пол с градиентом
                        double b = 1.0 - ((double)(y - screenHeight / 2) / (screenHeight / 2));
                        char floorShade;
                        if (b < 0.25)       floorShade = '#';
                        else if (b < 0.5)   floorShade = 'x';
                        else if (b < 0.75)  floorShade = '.';
                        else if (b < 0.9)   floorShade = '-';
                        else                floorShade = ' ';
                        screen[y * screenWidth + x] = floorShade;
                    }
                }
            }
    
            // Отрисовка игрока и HUD
            string stats = $"X={playerX:0.00}, Y={playerY:0.00}, Angle={playerAngle:0.00}  WASD - движение, Q/E - поворот";
            for (int i = 0; i < stats.Length; i++)
                screen[i] = stats[i];
    
            Console.SetCursorPosition(0, 0);
            Console.Write(screen);
        }
    
        static void HandleInput()
        {
            if (!Console.KeyAvailable)
                return;
    
            var key = Console.ReadKey(true).Key;
    
            switch (key)
            {
                case ConsoleKey.A: // Влево (странь)
                    playerAngle -= 0.1;
                    break;
                case ConsoleKey.D: // Вправо (странь)
                    playerAngle += 0.1;
                    break;
                case ConsoleKey.W: // Вперед
                    playerX += Math.Sin(playerAngle) * 0.5;
                    playerY += Math.Cos(playerAngle) * 0.5;
                    if (IsWall(playerX, playerY))
                    {
                        playerX -= Math.Sin(playerAngle) * 0.5;
                        playerY -= Math.Cos(playerAngle) * 0.5;
                    }
                    break;
                case ConsoleKey.S: // Назад
                    playerX -= Math.Sin(playerAngle) * 0.5;
                    playerY -= Math.Cos(playerAngle) * 0.5;
                    if (IsWall(playerX, playerY))
                    {
                        playerX += Math.Sin(playerAngle) * 0.5;
                        playerY += Math.Cos(playerAngle) * 0.5;
                    }
                    break;
                case ConsoleKey.Q: // Поворот влево
                    playerAngle -= 0.1;
                    break;
                case ConsoleKey.E: // Поворот вправо
                    playerAngle += 0.1;
                    break;
            }
        }
    
        static bool IsWall(double x, double y)
        {
            int ix = (int)x;
            int iy = (int)y;
            if (ix < 0 || ix >= mapWidth || iy < 0 || iy >= mapHeight)
                return true;
            return map[iy][ix] == '#';
        }
    }
    

    Как играть

    • W/S — движение вперёд/назад
    • A/D или Q/E — поворот влево/вправо
    • Цель — исследовать лабиринт, избегая стен.

    Как это работает

    • Используется упрощённый алгоритм raycasting — для каждого столбца экрана "луч" от игрока проверяет, где он столкнётся со стеной.
    • Высота стены на экране зависит от расстояния до неё — создаётся эффект глубины.
    • Используются символы с разной плотностью для имитации теней.
    • Игрок может двигаться и поворачивать, столкновения со стенами предотвращаются.

    Если хотите, могу помочь расширить эту игру — добавить врагов, предметы, улучшить графику и т.д.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.