Go Back   Champions of Regnum > Español > La Taberna

La Taberna Un lugar para conversar sobre casi cualquier tema

Reply
 
Thread Tools Display Modes
Old 09-19-2008, 08:45 PM   #21
Roldier
Banned
 
Roldier's Avatar
 
Join Date: Mar 2008
Location: Vivo en el foro.¡¡Que alguien me pase una almohada!!
Posts: 100
Roldier is on a distinguished road
Default

Quote:
Originally Posted by dragokaos
P0r qu3 n0 3st0y 100 % s3gur0 conf1rmam3 si 3r3s tu O.O"???

Es posible.... Dejame 60 minutos para pensarlo....
Roldier no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:45 PM   #22
arlick
Duke
 
arlick's Avatar
 
Join Date: Jan 2007
Posts: 3,939
arlick is a jewel in the rougharlick is a jewel in the rougharlick is a jewel in the rough
Default

que poco se de python T.T

the other!!

en la función if __name__ == '__main__':, puedo acceder al caracter que halla debajo de la posición actual del cursor? no se como hacerlo...
__________________
"Nunca un científico ha quemado a un religioso por afirmar a Dios sin pruebas". Manuel Toharia
"uno empieza a darse cuenta que eso de no hacer ejercicio, comer y beber como si fuese la ultima cena y mantener la figura ya no existe...". Maryan
arlick no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:46 PM   #23
Nidhug
Banned
 
Nidhug's Avatar
 
Join Date: Mar 2008
Location: Traficando con chimerin
Posts: 264
Nidhug is on a distinguished road
Default

Quote:
Originally Posted by Roldier
Es posible.... Dejame 60 minutos para pensarlo....
Te doy 60 segundos y contando 59, 58 , 57 ,56,55,.....
Nidhug no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:48 PM   #24
Roldier
Banned
 
Roldier's Avatar
 
Join Date: Mar 2008
Location: Vivo en el foro.¡¡Que alguien me pase una almohada!!
Posts: 100
Roldier is on a distinguished road
Default

Quote:
Originally Posted by dragokaos
Te doy 60 segundos y contando 59, 58 , 57 ,56,55,.....

Mira por donde me paso tus 60 segs: Forro
Roldier no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:51 PM   #25
Nidhug
Banned
 
Nidhug's Avatar
 
Join Date: Mar 2008
Location: Traficando con chimerin
Posts: 264
Nidhug is on a distinguished road
Default

Quote:
Originally Posted by Roldier
Mira por donde me paso tus 60 segs: Forro
El link esta mal
Nidhug no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:55 PM   #26
arlick
Duke
 
arlick's Avatar
 
Join Date: Jan 2007
Posts: 3,939
arlick is a jewel in the rougharlick is a jewel in the rougharlick is a jewel in the rough
Default

conseguido

Code:
import curses

FOV_RADIUS = 10

dungeon =  ["###########################################################",
            "#...........#.............................................#",
            "#...........#........#....................................#",
            "#.....................#...................................#",
            "#....####..............#..................................#",
            "#.......#.......................#####################.....#",
            "#.......#...........................................#.....#",
            "#.......#...........##..............................#.....#",
            "#####........#......##..........##################..#.....#",
            "#...#...........................#................#..#.....#",
            "#...#............#..............#................#..#.....#",
            "#...............................#..###############..#.....#",
            "#...............................#...................#.....#",
            "#...............................#...................#.....#",
            "#...............................#####################.....#",
            "#.........................................................#",
            "#.........................................................#",
            "###########################################################"]

class Map(object):
    # Multipliers for transforming coordinates to other octants:
    mult = [
                [1,  0,  0, -1, -1,  0,  0,  1],
                [0,  1, -1,  0,  0, -1,  1,  0],
                [0,  1,  1,  0,  0, -1, -1,  0],
                [1,  0,  0,  1, -1,  0,  0, -1]
            ]
    def __init__(self, map):
        self.data = map
        self.width, self.height = len(map[0]), len(map)
        self.light = []
        for i in range(self.height):
            self.light.append([0] * self.width)
        self.flag = 0
    def square(self, x, y):
        return self.data[y][x]
    def blocked(self, x, y):
        return (x < 0 or y < 0
                or x >= self.width or y >= self.height
                or self.data[y][x] == "#")
    def lit(self, x, y):
        return self.light[y][x] == self.flag
    def set_lit(self, x, y):
        if 0 <= x < self.width and 0 <= y < self.height:
            self.light[y][x] = self.flag
    def _cast_light(self, cx, cy, row, start, end, radius, xx, xy, yx, yy, id):
        "Recursive lightcasting function"
        if start < end:
            return
        radius_squared = radius*radius
        for j in range(row, radius+1):
            dx, dy = -j-1, -j
            blocked = False
            while dx <= 0:
                dx += 1
                # Translate the dx, dy coordinates into map coordinates:
                X, Y = cx + dx * xx + dy * xy, cy + dx * yx + dy * yy
                # l_slope and r_slope store the slopes of the left and right
                # extremities of the square we're considering:
                l_slope, r_slope = (dx-0.5)/(dy+0.5), (dx+0.5)/(dy-0.5)
                if start < r_slope:
                    continue
                elif end > l_slope:
                    break
                else:
                    # Our light beam is touching this square; light it:
                    if dx*dx + dy*dy < radius_squared:
                        self.set_lit(X, Y)
                    if blocked:
                        # we're scanning a row of blocked squares:
                        if self.blocked(X, Y):
                            new_start = r_slope
                            continue
                        else:
                            blocked = False
                            start = new_start
                    else:
                        if self.blocked(X, Y) and j < radius:
                            # This is a blocking square, start a child scan:
                            blocked = True
                            self._cast_light(cx, cy, j+1, start, l_slope,
                                             radius, xx, xy, yx, yy, id+1)
                            new_start = r_slope
            # Row is scanned; do next row unless last square was blocked:
            if blocked:
                break
    def do_fov(self, x, y, radius):
        "Calculate lit squares from the given location and radius"
        self.flag += 1
        for oct in range(8):
            self._cast_light(x, y, 1, 1.0, 0.0, radius,
                             self.mult[0][oct], self.mult[1][oct],
                             self.mult[2][oct], self.mult[3][oct], 0)
    def display(self, s, X, Y):
        "Display the map on the given curses screen (utterly unoptimized)"
        dark, lit = curses.color_pair(8), curses.color_pair(7) | curses.A_BOLD    
        for x in range(self.width):
            for y in range(self.height):
                if self.lit(x, y):
                    attr = lit
                else:
                    attr = dark
                if x == X and y == Y:
                    ch = '@'
                    attr = lit
                else:
                    ch = self.square(x, y)
                s.addstr(y, x, ch, attr)
        s.refresh()
        

def color_pairs():
    c = []
    for i in range(1, 16):
        curses.init_pair(i, i % 8, 0)
        if i < 8:
            c.append(curses.color_pair(i))
        else:
            c.append(curses.color_pair(i) | curses.A_BOLD)
    return c


if __name__ == '__main__':
    try:
        s = curses.initscr()
        curses.start_color()
        curses.noecho()
        curses.cbreak()
        color_pairs()
        s.keypad(1)
        x, y = 36, 13
        map = Map(dungeon)
        while True:
            map.do_fov(x, y, FOV_RADIUS)
            map.display(s, x, y)
            k = s.getch()
            if k == 27:
                break
            elif k == 259:
		y -= 1
		if map.blocked(x, y):
		    y += 1
            elif k == 258:
                y += 1
		if map.blocked(x, y):
		    y -= 1
            elif k == 260:
                x -= 1
		if map.blocked(x, y):
		    x += 1
            elif k == 261:
                x += 1
	    	if map.blocked(x, y):
		    x -= 1
    finally:
        s.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
        print "Normal termination."
__________________
"Nunca un científico ha quemado a un religioso por afirmar a Dios sin pruebas". Manuel Toharia
"uno empieza a darse cuenta que eso de no hacer ejercicio, comer y beber como si fuese la ultima cena y mantener la figura ya no existe...". Maryan
arlick no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:58 PM   #27
theotherhiveking
Count
 
Join Date: May 2007
Posts: 1,452
theotherhiveking has a spectacular aura abouttheotherhiveking has a spectacular aura abouttheotherhiveking has a spectacular aura about
Default

Quote:
Originally Posted by arlick
que poco se de python T.T

the other!!

en la función if __name__ == '__main__':, puedo acceder al caracter que halla debajo de la posición actual del cursor? no se como hacerlo...

Yo tampoco O_o

Seguro se puede hacer con curses.

No se.. podes importar curses y luego haces 'dir(curses)', miras los nombres y podes hacer 'print curses.lo_que_sea.__doc__' por si tiene algo de documentacion verla.

Edit: a bue.. a ver
__________________
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
theotherhiveking no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:59 PM   #28
Roldier
Banned
 
Roldier's Avatar
 
Join Date: Mar 2008
Location: Vivo en el foro.¡¡Que alguien me pase una almohada!!
Posts: 100
Roldier is on a distinguished road
Default

Quote:
Originally Posted by arlick
conseguido

Code:
import curses

FOV_RADIUS = 10

dungeon =  ["###########################################################",
            "#...........#.............................................#",
            "#...........#........#....................................#",
            "#.....................#...................................#",
            "#....####..............#..................................#",
            "#.......#.......................#####################.....#",
            "#.......#...........................................#.....#",
            "#.......#...........##..............................#.....#",
            "#####........#......##..........##################..#.....#",
            "#...#...........................#................#..#.....#",
            "#...#............#..............#................#..#.....#",
            "#...............................#..###############..#.....#",
            "#...............................#...................#.....#",
            "#...............................#...................#.....#",
            "#...............................#####################.....#",
            "#.........................................................#",
            "#.........................................................#",
            "###########################################################"]

class Map(object):
    # Multipliers for transforming coordinates to other octants:
    mult = [
                [1,  0,  0, -1, -1,  0,  0,  1],
                [0,  1, -1,  0,  0, -1,  1,  0],
                [0,  1,  1,  0,  0, -1, -1,  0],
                [1,  0,  0,  1, -1,  0,  0, -1]
            ]
    def __init__(self, map):
        self.data = map
        self.width, self.height = len(map[0]), len(map)
        self.light = []
        for i in range(self.height):
            self.light.append([0] * self.width)
        self.flag = 0
    def square(self, x, y):
        return self.data[y][x]
    def blocked(self, x, y):
        return (x < 0 or y < 0
                or x >= self.width or y >= self.height
                or self.data[y][x] == "#")
    def lit(self, x, y):
        return self.light[y][x] == self.flag
    def set_lit(self, x, y):
        if 0 <= x < self.width and 0 <= y < self.height:
            self.light[y][x] = self.flag
    def _cast_light(self, cx, cy, row, start, end, radius, xx, xy, yx, yy, id):
        "Recursive lightcasting function"
        if start < end:
            return
        radius_squared = radius*radius
        for j in range(row, radius+1):
            dx, dy = -j-1, -j
            blocked = False
            while dx <= 0:
                dx += 1
                # Translate the dx, dy coordinates into map coordinates:
                X, Y = cx + dx * xx + dy * xy, cy + dx * yx + dy * yy
                # l_slope and r_slope store the slopes of the left and right
                # extremities of the square we're considering:
                l_slope, r_slope = (dx-0.5)/(dy+0.5), (dx+0.5)/(dy-0.5)
                if start < r_slope:
                    continue
                elif end > l_slope:
                    break
                else:
                    # Our light beam is touching this square; light it:
                    if dx*dx + dy*dy < radius_squared:
                        self.set_lit(X, Y)
                    if blocked:
                        # we're scanning a row of blocked squares:
                        if self.blocked(X, Y):
                            new_start = r_slope
                            continue
                        else:
                            blocked = False
                            start = new_start
                    else:
                        if self.blocked(X, Y) and j < radius:
                            # This is a blocking square, start a child scan:
                            blocked = True
                            self._cast_light(cx, cy, j+1, start, l_slope,
                                             radius, xx, xy, yx, yy, id+1)
                            new_start = r_slope
            # Row is scanned; do next row unless last square was blocked:
            if blocked:
                break
    def do_fov(self, x, y, radius):
        "Calculate lit squares from the given location and radius"
        self.flag += 1
        for oct in range(8):
            self._cast_light(x, y, 1, 1.0, 0.0, radius,
                             self.mult[0][oct], self.mult[1][oct],
                             self.mult[2][oct], self.mult[3][oct], 0)
    def display(self, s, X, Y):
        "Display the map on the given curses screen (utterly unoptimized)"
        dark, lit = curses.color_pair(8), curses.color_pair(7) | curses.A_BOLD    
        for x in range(self.width):
            for y in range(self.height):
                if self.lit(x, y):
                    attr = lit
                else:
                    attr = dark
                if x == X and y == Y:
                    ch = '@'
                    attr = lit
                else:
                    ch = self.square(x, y)
                s.addstr(y, x, ch, attr)
        s.refresh()
        

def color_pairs():
    c = []
    for i in range(1, 16):
        curses.init_pair(i, i % 8, 0)
        if i < 8:
            c.append(curses.color_pair(i))
        else:
            c.append(curses.color_pair(i) | curses.A_BOLD)
    return c


if __name__ == '__main__':
    try:
        s = curses.initscr()
        curses.start_color()
        curses.noecho()
        curses.cbreak()
        color_pairs()
        s.keypad(1)
        x, y = 36, 13
        map = Map(dungeon)
        while True:
            map.do_fov(x, y, FOV_RADIUS)
            map.display(s, x, y)
            k = s.getch()
            if k == 27:
                break
            elif k == 259:
        y -= 1
        if map.blocked(x, y):
            y += 1
            elif k == 258:
                y += 1
        if map.blocked(x, y):
            y -= 1
            elif k == 260:
                x -= 1
        if map.blocked(x, y):
            x += 1
            elif k == 261:
                x += 1
            if map.blocked(x, y):
            x -= 1
    finally:
        s.keypad(0)
        curses.echo()
        curses.nocbreak()
        curses.endwin()
        print "Normal termination."

Pero si solo cambio coordenadas.... Que hay que saber para cambiar y para que sirve ese codigo? =o
Roldier no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 08:59 PM   #29
arlick
Duke
 
arlick's Avatar
 
Join Date: Jan 2007
Posts: 3,939
arlick is a jewel in the rougharlick is a jewel in the rougharlick is a jewel in the rough
Default

Quote:
Originally Posted by theotherhiveking
Yo tampoco O_o

Seguro se puede hacer con curses.

No se.. podes importar curses y luego haces 'dir(curses)', miras los nombres y podes hacer 'print curses.lo_que_sea.__doc__' por si tiene algo de documentacion verla.
revisa mi último (anterior) post ^^
__________________
"Nunca un científico ha quemado a un religioso por afirmar a Dios sin pruebas". Manuel Toharia
"uno empieza a darse cuenta que eso de no hacer ejercicio, comer y beber como si fuese la ultima cena y mantener la figura ya no existe...". Maryan
arlick no ha iniciado sesión   Reply With Quote
Old 09-19-2008, 09:01 PM   #30
theotherhiveking
Count
 
Join Date: May 2007
Posts: 1,452
theotherhiveking has a spectacular aura abouttheotherhiveking has a spectacular aura abouttheotherhiveking has a spectacular aura about
Default

Ya lo vi, arlick gana. El premio es 2 puntos de karma, cuando te pueda dar por hace ya siglos que no le puedo dar a nadie.

Pongo otro?
__________________
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
theotherhiveking no ha iniciado sesión   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:34 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
NGD Studios 2002-2024 © All rights reserved