Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Roguelike in Haskell

Name: dddddddddddddddddddddddddd 2007-04-11 7:21 ID:Vgzv11QG

I'm making one ^_^

Just to show off my elite level building skillz

*Level> pLevel $ foldObjs emptyLevel [(Way True 10, 23, 14), (Way False 5, 23, 9) ,(Way True 5, 15, 4), (Room (15,12), 1, 1), (Room (10, 7), 19, 3), (Room (40,7), 32, 10)]
                                                                               
 ---------------                                                               
 |.............|                                                               
 |.............|   ----------                                                  
 |.............#####........|                                                  
 |.............|   |........|                                                  
 |.............|   |........|                                                  
 |.............|   |........|                                                  
 |.............|   |........|                                                  
 |.............|   ----#-----                                                  
 |.............|       #        ----------------------------------------       
 |.............|       #        |......................................|       
 ---------------       #        |......................................|       
                       #        |......................................|       
                       ##########......................................|       
                                |......................................|       
                                ----------------------------------------       
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
*Level>

Name: Anonymous 2007-04-11 7:33 ID:WZvz0yqV

Needs more non-rectangular rooms.

Name: Anonymous 2007-04-11 7:55 ID:W8YLrdRl

Needs more cowbell

Name: Anonymous 2007-04-11 8:41 ID:rfxdz013

>>1
is this supposed to impress me?
why dont you post the implementation of pLevel LOL.

Name: Anonymous 2007-04-11 8:53 ID:Vgzv11QG

>>2
FAGGOT

*Level> let crossRoom = let box = Room (7,5) in foldObjs1 [(TPath GenericFloor True 5, 11, 9), (TPath GenericFloor False 3, 16, 6), (TPath GenericFloor False 3, 10, 6),(TPath GenericFloor True 5, 11, 5), (box,10,5), (box,5,5),(box,15,5), (box,10,1), (box,10,9)]
*Level> printLevel crossRoom
                                                                               
          -------                                                              
          |.....|                                                              
          |.....|                                                              
          |.....|                                                              
     ------.....------                                                         
     |...............|                                                         
     |...............|                                                         
     |...............|                                                         
     ------.....------                                                         
          |.....|                                                              
          |.....|                                                              
          |.....|                                                              
          -------                                                              
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
*Level>


And no this isn't supposed to be user-editable.

Name: Anonymous 2007-04-11 8:54 ID:Vgzv11QG

>>4
levelToString :: Level -> [String]
levelToString = map2 tileToChar . dungeon

printLevel :: Level -> IO ()
printLevel = putStr . unlines . levelToString


???

Name: Anonymous 2007-04-11 8:56 ID:WZvz0yqV

>>5
Very good. Now show us a goatse-shaped level.

Name: Anonymous 2007-04-11 8:56 ID:rfxdz013

>>6
is this supposed to impress me?
why dont you post the implementation of tileToChar LOL.
why dont you post the implementation of dungeon LOL.

Name: Anonymous 2007-04-11 9:39 ID:bW7pC3Kg

Angband-style dungeon for the lazy ;)
main = getStdGen >>= putStrLn . show . fillBox (10, 10) (15, 15) (Tile Wall) . fst . randomMapG (80, 24)

##..##..#...##.....#######..##.# #.##.###.##.######.#.##.#.###.##.#..#...#..##..
..##.####...#.#...#...##..#.#.######.##...##.....#...##....#.#.#.....##.#.##.#.#
......#...#.....###...##.#.#.#..#.#..##.##.#.#.##...##.#......##.#.#.......###..
...##.###.#..#...#..###..###.###..#.##.##...#.#.##.#.#..#.#.#....##.#....#.# #..
.####.#..#..###..##.........#.###.#..###.#...#.#....#####...#.##.###..#.##.#####
##.###..####.###...#..##.....##.##.##.#.####...###.#.#.###...######..##.#..##...
.#..#.#...#######......###.#....#.####.#..#...#..###.####...#.#.###....#..##..#.
.###.#..###...#.##...###..##.......##.#####.##.##.#....#..##.......#..##.##.##..
##.##.##.#..##..#...###.#..####...###.#.##.#..#.##.#..##.#.##.#...#..##.#.######
#.#..#.###...#..#..#####...##.##...#...#..##..####.#####..#.##..#.#..#..#.#...#.
####...#.######......##.##.....##....#..#.#.#.#..#.....#.#.#.#..#..###..###.#...
#.#..#.#.##   #...###.##.##.#.####...##.#..#####.##..#...#.###......#.#..###...#
#..##.#...#   #.#.######..############..#.#.#...###..#.##..###.#....##..###.#...
.######.#.#   ###..####.#.###.#..##.#..##...#........##...##...###......####.###
...##.....###  #..###..#####.##.#..####.#...#.....#..#.###..####.#.##.#.#..#...#
#.##...###..####...#...##.#..#.#..#.###.#.####.....##..#.####.#.#####.....#.....
#...#####.##......#..###...#...#.####.###.#.#.#####..#.######..#.#.#.##.##.##.##
.#.##..###....#.##.##...#.###.....##.#..#.##..# #...#...##.##..###..#..####.##..
...#..##.##.#..##..#....##.##.##...#.#...#.#.######..#.#....#.#####.#..#..#.#..#
.#.#.#.#.#.#...#.#.#.##..#.#..##.....##.#.#.....##..#..#...#....##.###....#..##.
##.#..##....#.#.####..##.#......#.#....#.#.####.#.#.#####....##...#..##.#####.#.
...##..##.#.#....#..#######...##..#..#..#.#.####..##.#.#...#.##.###.##..###..##.
.##.##.#######..#.###..#.###..#....#...#......#..#.###..####..####.#####.#...#.#
#####..##.#.##...###.#.##.#..###...##.###.##......#..#.##..###.##.## #..#.....##

Name: Anonymous 2007-04-11 9:54 ID:/tU3b9ZU

x <=> y

Name: Anonymous 2007-04-11 12:34 ID:Heaven

>>9
Wow, that dungeon fails hard.

Name: Anonymous 2007-04-12 4:16 ID:rKYdamuA

>>11
Oh come on, I haven't even written a level generator yet.

It's probably a good idea to use something more abstract than tiles for the level generation process.

Name: Anonymous 2007-04-17 11:55 ID:v7YeOWaZ

>>12
I have now written a level generator.  Please bear in mind that the pathfinding algorithm (esp from Data.Graph.Inductive) does not have a penalty for diagonal movement, and will thusly use it a lot.  Also, I don't think I have ensured that the corridors keep away from the walls of the rooms.

*Main> main
                                                                               
                                                                               
                ####                                          ####             
                #..#####                                     ##..##            
               ##...##.#####                                ##....#            
              ##...........#                               ##.#...#            
             ##.#..........#                              ##.##...#            
            ##.##########.##                             ##.###...#            
      #### ##.##        ##.##                           ##.## #...#            
     ##..###.##          ##.##                         ##.##  #####            
     #....#.##            ##.##                       ##.##                    
     #...#.##              ##.##                     ##.##                     
     #...###                ##.##                   ##.##                      
     #...#                   ##.##                 ##.##                       
     #####                    ##.##               ##.##                        
                               ##.##             ##.##                         
                                ##.##           ##.##                          
                                 ##.##         ##.##                           
                                  ##.##       ##.##                            
                                   ##.##     ##.##                             
                                    ##.##   ##.##                              
                                     ##.## ##.##                               
                                      ##.###.##                                
                                       ##...##

Name: Anonymous 2007-04-17 11:59 ID:FKR6Bpsx

>>13
Eh, just generate Nethack-like levels. Then there's no worry about corridors getting too close to rooms. (Also, nethack style levels look less busy.)

Name: Anonymous 2007-04-17 12:13 ID:v7YeOWaZ

>>14
It's annoying having to care about what's a room and what is not!

Hmm... I could assign a higher weight to tiles next to open tiles, that would keep corridors separate as well!

Name: Anonymous 2007-04-17 17:28 ID:ImMm6e2X

>>13
darcs get ???

Name: Anonymous 2007-04-17 17:45 ID:iFsiwib7

Why not just copy the room-generating algorithm from NetHack's code? Of course it would need to be HASKELLIFIED but you'd see about weighting issues.

Name: Anonymous 2007-04-17 21:21 ID:FKR6Bpsx

>>17
Then you'd get Nethack levels. A new roguelike obviously needs its own feel, rather than lifting Nethack's verbatim.

Name: Anonymous 2007-04-17 22:15 ID:qCX9sxf1

>>1
source code or it didn't happen

Name: Anonymous 2007-04-18 2:39 ID:4cFEfsE+

>>17
I take it you have never looked at NetHack's level generation?  (Just finding it is a challenge in itself.)

>>16
I'm afraid you'd punch me in the face if you saw the code.  It's like THREE HUNDRED lines of code.

Name: Anonymous 2007-04-18 2:42 ID:QHvHeZag

>>17 has obviously never seen NetHack source code. ughhh

Name: Anonymous 2007-04-18 3:00 ID:QHvHeZag

>>16
I'm interested how you turn the level into a Data.Graph.Inductive. Presumably you then use Data.Graph.Inductive.Query.SP?

Name: Anonymous 2007-04-18 3:34 ID:QHvHeZag

>>22 er >>20

Name: Anonymous 2007-04-18 3:38 ID:C5Aoeq+y

>>20
Was >>16 meant to quote >>19? I still want to see it.

Also, I'm not >>17, but yes, I tried finding NetHack's level generation code and I couldn't :-(. Granted I didn't try very hard, but it's certainly not in an obvious location.

Speaking of which, can anyone point me to where the level generation is in the source code?

Name: Anonymous 2007-04-18 4:08 ID:iBr/ioVT

>>1
why do that when the shit been ported so many times already in the last 20years?

*bang*

..33 and counting.

Name: Anonymous 2007-04-18 4:22 ID:QHvHeZag

>>25
Because we're not all EXPERT JAVA DEVELOPERS working on ENTERPRISE READY MULTIMILLION LOC WEBAPPS

Name: Anonymous 2007-04-18 4:27 ID:iBr/ioVT

>>26
it's called unix. you may have heard of it?

Name: Anonymous 2007-04-18 6:38 ID:4cFEfsE+

>>22
I just make a node for every tile (using y*w+x as node id) and then add edges between all adjacent tiles.

If I need to do something like pathfinding, I only add nodes that satisfy certain conditions, such as being floors.

>>24
Speaking of which, can anyone point me to where the level generation is in the source code?

Dunno lol, I think it's spread over several files.  Ah, the mk*.c files.

Name: Anonymous 2007-04-18 7:19 ID:QHvHeZag

>>28
Is your code as ugly as mine? I'm trying to figure out if roguelike code is inherently ugly, or I'm doing it wrong.

e.g.
displayInventory :: H ()
displayInventory = do
    gs <- get
    let is = (inventory . player) gs
    outStr 0 0 " Your inventory: "
    mapM_ (\(n,l) -> outStr 3 n ((['a'..'z'] !! (n-1)) : ". " ++ (itemname l)))
        (zip [1..] (take 22 is))
    io $ C.refresh

Name: Anonymous 2007-04-18 7:28 ID:4cFEfsE+

>>29
I'm afraid I haven't got any terribly bad-looking examples!

Oh, wait...

randomValues :: RandomGen g => g -> ((Int, Int, Int, Int, Compass), g)
randomValues g =
  let (x, g1) = randomR (2, 76) g -- Magic numbers, motherfucker, do you use them?
      (y, g2) = randomR (2, 20) g1
      (w, g3) = randomR (2, 10) g2
      (h, g4) = randomR (2, 6) g3
      (c, g5) = random g4
  in ((x, y, w, h, c), g5)

Name: Anonymous 2007-04-18 13:05 ID:4cFEfsE+

Looks a bit better with only orthogonal connections.  Still some random issues with unconnected rooms, corridors that trail off into the edges, and other fun stuff :)
*Main> main
                                                                               
                                                                               
                                                                               
                                                                               
                                                           ###                 
                                                      ######.#####             
                                                      #..........#             
                                                      #..........#             
    ############                                      #..........#             
    #..........#                                      #..........#             
    #..........##                                     ######.#####             
    #...........#                                          #.#                 
    #...........#               ####                       #.#                 
    ###########.#              ##..#                     ###.#                 
              #.#              #...#                     #...#########         
              #.#              #...#                     #...........#         
              #.#              #.#.#                     #...........#         
         ######.#              #.#.#                     #...........# ###     
         #......#              #.#.#######################.......#######.#     
         #......################.#.......................................#     
         #.......................#########################################     
         #......########.....#####                                             
         #...............#####                                                 
         #################

Name: Anonymous 2007-04-18 13:44 ID:zGR/KFF7

FUCK YOUR SHITTY HASKELL CODE ID WRITE THIS IN C?

Name: Anonymous 2007-04-18 14:55 ID:9dZe8HuP

>>29
You could do "is <- gets (inventory . player)" rather than the get and let. Assuming that you're using the State monad.

Name: Anonymous 2007-04-18 15:21 ID:QHvHeZag

>>33
Yeah. RWST actually.

Name: Anonymous 2007-04-19 6:19 ID:BMLHNaX3

Quack quack motherfuckers

Name: Anonymous 2007-04-19 6:43 ID:WjtYJ7dF

You hit Hurr'k Or'drl!

    ---------         ------------------------
    |..)c>..|         |.................?....|
    |.....<.|         |......................|
    ----@----         |...................%..------------
        T             -----.............................|
    #####                 |.............................|
    #                     ----------------------#--------
    #                                           #
    #                                           #
    #                                           #           #
    #                                           #           #
    #   ------------------------                #           #
    #   |........~~~~~~~~~.....|                #           #
    #   |...~~~~~~~~~~~.........#############################
    #   |.....~~~~~~...........|                #           #
    ####.......................|        --------.------     #
        ------------------------        |.............|     #
                                        |.............|
                                        |.............|
                                        ---------------


Monos, healthy                                                               64


how 2 implement line-of-sight??1

Name: Anonymous 2007-04-19 8:55 ID:1SlyAwrT

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░████████████░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░████████████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░████████████████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░████████████████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░████░░██████░░██████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██░░██░░██░░██░░████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██░░██░░██░░██░░████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██░░▒▒▒▒▒▒▒▒██░░████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██░░▒▒▒▒▒▒▒▒░░░░██████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░██████████░░░░░░░░░░░░
░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░░░██████████░░░░░░░░░░
░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░
░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░
░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░░░██████████░░░░░░░░
░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░░░██████████░░░░░░░░
░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░░░░░░░░░██████████░░░░░░░░
░░░░░░░░░░██████░░░░░░░░░░░░░░░░░░░░░░░░░░██████████░░░░░░░░
░░░░░░░░░░▒▒▒▒██░░░░░░░░░░░░░░░░░░░░░░░░░░██████████░░░░░░░░
░░░░░░░░░░▒▒▒▒▒▒██░░░░░░░░░░░░░░░░░░░░░░▒▒████████▒▒░░░░░░░░
░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░░░░░░░░░░░░░░░░░░▒▒▒▒████▒▒▒▒░░░░░░░░
░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒████░░░░░░░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░
░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████░░░░░░░░░░░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░
░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░
░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░██████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░
░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████████████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░
░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████████████████▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░
░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░░░██▒▒▒▒▒▒▒▒░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░░░░░░░░░░░██░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

Name: Anonymous 2007-04-19 18:23 ID:7c7yA9iO

>>37
that doesn't look like a duck to me... and i doubt it quacks like one either...

Name: Anonymous 2007-04-20 9:03 ID:L41CZWK3

>>36
'tis a great challenge!

The easiest way is probably to trace a line from the point of sight to every tile on the map.  If the line intersects a solid tile, do not draw the final tile, else do so.

If you are lucky, it might look good right away!

Name: Anonymous 2007-04-20 9:45 ID:1CwSmVRF

>>38
Are ducks touring-complete?

Name: Anonymous 2007-04-20 17:29 ID:FkoSafTg

>>40
Yes, they go out then come back.

Name: Anonymous 2007-04-20 18:06 ID:TwvI+KHK

>>41

Idiot. We're talking about TOURING COMPLETENESS. A fundamental concept in computer science invented by Anal Touring.

Fuck your ducks.

Name: Anonymous 2007-04-20 18:32 ID:x0xFDaAH

>>42
Anal Touring sounds kinky.

Name: Anonymous 2007-04-20 19:06 ID:llPLX8Bt

>>43
Like something Alan Turing would have been into ...

Name: Anonymous 2007-04-20 19:25 ID:TwvI+KHK

>>44

True. He was homogeneous.

Name: Anonymous 2008-08-30 2:08

Xmonad

Name: Anonymous 2008-08-30 7:14

Please, for the love of god, add doors, people; otherwise, it is acceptable and even almost awesome that you are roguing in haskell.  Also, I'm sorry, but the # for walls (including corridor walls) is a terrible eyesore.  Please stop that.

Also, there is no penalty for diagonal movement (at least in nethack and many other roguelikes), and, in fact, diagonal movement is considered faster.

As someone hinted earlier, the nethack level generation code is available in mklev.c and mkmaze.c.  It's actually pretty straightforward (at least from what I can tell in a couple of minutes of looking at it).

mklev.c's meat is pretty much to make the rooms, then build doors between them and connect with corridors.  Here is the make rooms code:
STATIC_OVL void
makerooms()
{
    boolean tried_vault = FALSE;

    /* make rooms until satisfied */
    /* rnd_rect() will returns 0 if no more rects are available... */
    while(nroom < MAXNROFROOMS && rnd_rect()) {
        if(nroom >= (MAXNROFROOMS/6) && rn2(2) && !tried_vault) {
            tried_vault = TRUE;
            if (create_vault()) {
                vault_x = rooms[nroom].lx;
                vault_y = rooms[nroom].ly;
                rooms[nroom].hx = -1;
           
        } else
            if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1))
            return;
    }
    return;
}

Name: Anonymous 2008-08-30 8:59

>>47
Door fan is butt-hurt.

Name: Anonymous 2008-08-30 9:33

old

Name: Anonymous 2008-08-30 9:35

Stupid fucking nomads.

Name: I hate doors 2008-08-30 12:40

>>47
I hate doors

Name: Anonymous 2010-11-14 9:46

Name: Anonymous 2010-11-27 5:50

Name: Anonymous 2010-11-28 0:49

Name: Anonymous 2010-12-17 1:34

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2010-12-21 14:42

Name: Anonymous 2011-02-02 23:00

Name: Sgt.Kabu柨kiman᤯衒 2012-05-29 0:07

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List