[SOLVED] Problem with sudoku minigame

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

[SOLVED] Problem with sudoku minigame

#1 Post by Endorphin » Sun Feb 26, 2012 9:05 am

Hi there, guys! =)

So, I'm back from working on something else and decided to script some minigames.
I edited >this wonderful puzzle script< so that it has 50 pieces and then started to work on the sudokuthingy.

For this, I edited the puzzlescript.
I can drag and drop the pieces but I'm having problems with the winning conditions.
Is there any way to edit the in a way that the player actually wins? D;
I especially have troubles because there are multiple ways to win - after all, every "3"-piece is the same.
(Would naming them in the same way solve this problem?)

However, this is my code so far:

Code: Select all

init python:
    
    def piece_dragged(drags, drop):
        
        if not drop:
            store.piecelist[(int(drags[0].drag_name[0]) * 10 + int(drags[0].drag_name[1]))][0] = drags[0].x
            store.piecelist[(int(drags[0].drag_name[0]) * 10 + int(drags[0].drag_name[1]))][1] = drags[0].y
            return
            
        store.movedpiece = int(drags[0].drag_name[0]) * 10 + int(drags[0].drag_name[1])
        store.movedplace = [int(drop.drag_name[0]), int(drop.drag_name[1])]
        
        return True

screen sudokusteine:
    
    draggroup:
        
        drag:
            drag_name "00"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[0]
            
        drag:
            drag_name "02"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[2]
         
        drag:
            drag_name "04"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[4]    
         
        drag:
            drag_name "05"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[5]    
            
        drag:
            drag_name "07"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[7]
            
        drag:
            drag_name "08"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[8]    
            
        drag:
            drag_name "10"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[0]
            
        drag:
            drag_name "11"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[1]
        
        drag:
            drag_name "14"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[4]     
            
        drag:
            drag_name "15"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[5]    
        
        drag:
            drag_name "16"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[6]    
        
        drag:
            drag_name "17"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[7]    
            
        drag:
            drag_name "18"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[8]    
            
        drag:
            drag_name "20"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[0]
            
        drag:
            drag_name "21"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[1]
            
        drag:
            drag_name "22"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[2]
            
        drag:
            drag_name "23"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[3]     
            
        drag:
            drag_name "26"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[6]      
         
        drag:
            drag_name "27"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[7]      
            
        drag:
            drag_name "28"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[8]       
            
        drag:
            drag_name "30"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[0]
            
        drag:
            drag_name "31"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[1]
        
        drag:
            drag_name "32"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[2]
        
        drag:
            drag_name "33"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[3]    
            
        drag:
            drag_name "36"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[6]      
         
        drag:
            drag_name "37"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[7]      
            
        drag:
            drag_name "38"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[8]  
                    
        drag:
            drag_name "41"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[1]
        
        drag:
            drag_name "45"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[5]      
            
        drag:
            drag_name "46"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[6]      
         
        drag:
            drag_name "47"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[7]      
            
        drag:
            drag_name "51"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[1]
        
        drag:
            drag_name "52"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[2]
        
        drag:
            drag_name "53"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[3]    
            
        drag:
            drag_name "54"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[4]      
        
        drag:
            drag_name "55"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[5]      
        
        drag:
            drag_name "56"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[6]      
            
        drag:
            drag_name "57"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[7]      
            
        drag:
            drag_name "61"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[1]
        
        drag:
            drag_name "65"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[5]
        
        drag:
            drag_name "67"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[7]    
            
        drag:
            drag_name "68"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[8]     
        
        drag:
            drag_name "70"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[0]
        
        drag:
            drag_name "72"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[2]
        
        drag:
            drag_name "73"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[3]    
            
        drag:
            drag_name "74"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[4]     
        
        drag:
            drag_name "75"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[5]
            
        drag:
            drag_name "76"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[6]    
            
        drag:
            drag_name "77"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[7] 
            
        drag:
            drag_name "80"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[0]
            
        drag:
            drag_name "81"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[1]
        
        drag:
            drag_name "83"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[3]  
            
        drag:
            drag_name "84"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[4]  
            
        drag:
            drag_name "85"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[5]      
            
        drag:
            drag_name "87"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[7]      
            
        drag:
            drag_name "88"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[8]  
            
        #################################    
        
        drag:
            drag_name "00 piece"
            child "Sudoku/Test.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[0][0] ypos piecelist[0][1]
            
        drag:
            drag_name "01 piece"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[1][0] ypos piecelist[1][1]
            
        drag:
            drag_name "02 piece"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[2][0] ypos piecelist[2][1]
            
        drag:
            drag_name "03 piece"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[3][0] ypos piecelist[3][1]
            
        drag:
            drag_name "07 piece"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[7][0] ypos piecelist[7][1]
            
        drag:
            drag_name "08 piece"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[8][0] ypos piecelist[8][1]
        ### 2  
        drag:
            drag_name "10 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[10][0] ypos piecelist[10][1]
            
        drag:
            drag_name "11 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[11][0] ypos piecelist[11][1]
            
        drag:
            drag_name "12 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[12][0] ypos piecelist[12][1]
            
        drag:
            drag_name "13 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[13][0] ypos piecelist[13][1]
            
        drag:
            drag_name "14 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[14][0] ypos piecelist[14][1]
            
        drag:
            drag_name "15 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[15][0] ypos piecelist[15][1]
            
        drag:
            drag_name "17 piece"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[17][0] ypos piecelist[17][1]
        ### 3    
        drag:
            drag_name "18 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[18][0] ypos piecelist[18][1]

        drag:
            drag_name "20 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[20][0] ypos piecelist[20][1]
            
        drag:
            drag_name "21 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[21][0] ypos piecelist[21][1]
            
        drag:
            drag_name "23 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[23][0] ypos piecelist[23][1]
            
        drag:
            drag_name "25 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[25][0] ypos piecelist[25][1]

        drag:
            drag_name "29 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[29][0] ypos piecelist[29][1]      
        
        drag:
            drag_name "30 piece"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[30][0] ypos piecelist[30][1]
        ### 4
        drag:
            drag_name "32 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[32][0] ypos piecelist[32][1]

        drag:
            drag_name "34 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[34][0] ypos piecelist[34][1]
            
        drag:
            drag_name "35 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[35][0] ypos piecelist[35][1]
            
        drag:
            drag_name "36 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[36][0] ypos piecelist[36][1]
            
        drag:
            drag_name "37 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[37][0] ypos piecelist[37][1]

        drag:
            drag_name "41 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[41][0] ypos piecelist[41][1]

        drag:
            drag_name "43 piece"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[43][0] ypos piecelist[43][1]
        ### 5    
        drag:
            drag_name "44 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[44][0] ypos piecelist[44][1]
            
        drag:
            drag_name "45 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[45][0] ypos piecelist[45][1]
            
        drag:
            drag_name "46 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[46][0] ypos piecelist[46][1]

        drag:
            drag_name "49 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[49][0] ypos piecelist[49][1]    
        
        drag:
            drag_name "50 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[50][0] ypos piecelist[50][1]        
            
        drag:
            drag_name "51 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[51][0] ypos piecelist[51][1]     
            
        drag:
            drag_name "52 piece"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[52][0] ypos piecelist[52][1]     
        ### 6
        drag:
            drag_name "53 piece"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[53][0] ypos piecelist[53][1]     
            
        drag:
            drag_name "55 piece"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[55][0] ypos piecelist[55][1] 
            
        drag:
            drag_name "56 piece"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[56][0] ypos piecelist[56][1]     
            
        drag:
            drag_name "57 piece"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[57][0] ypos piecelist[57][1]     
            
        drag:
            drag_name "58 piece"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[58][0] ypos piecelist[58][1]     
        ### 7 
        drag:
            drag_name "59 piece"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[59][0] ypos piecelist[59][1]     
            
        drag:
            drag_name "61 piece"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[61][0] ypos piecelist[61][1]     
         
        drag:
            drag_name "63 piece"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[63][0] ypos piecelist[63][1]      
            
        drag:
            drag_name "64 piece"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[64][0] ypos piecelist[64][1]      
            
        drag:
            drag_name "66 piece"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[66][0] ypos piecelist[66][1]   
        ### 8    
        drag:
            drag_name "67 piece"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[67][0] ypos piecelist[67][1]      
            
        drag:
            drag_name "68 piece"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[68][0] ypos piecelist[68][1]      
            
        drag:
            drag_name "69 piece"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[69][0] ypos piecelist[69][1]      
            
        drag:
            drag_name "70 piece"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[70][0] ypos piecelist[70][1]  
            
        drag:
            drag_name "71 piece"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[71][0] ypos piecelist[71][1]      
            
        drag:
            drag_name "72 piece"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[72][0] ypos piecelist[72][1]  
        ### 9    
        drag:
            drag_name "73 piece"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[73][0] ypos piecelist[73][1]      
            
        drag:
            drag_name "74 piece"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[74][0] ypos piecelist[74][1]      
            
        drag:
            drag_name "75 piece"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[75][0] ypos piecelist[75][1]      
            
        drag:
            drag_name "78 piece"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[78][0] ypos piecelist[78][1]      
        
        drag:
            drag_name "80 piece"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[80][0] ypos piecelist[80][1]      
            
label sudokuauswertung:
    call screen sudokusteine
    if ([coorlistx[movedplace[0]], coorlisty[movedplace[1]]] in piecelist):
        python:
            t1 = piecelist[movedpiece]
            t2 = piecelist.index([coorlistx[movedplace[0]], coorlisty[movedplace[1]]])
            piecelist[movedpiece] = [coorlistx[movedplace[0]],coorlisty[movedplace[1]]]
            piecelist[t2] = t1
    else:
        $ piecelist[movedpiece] = [coorlistx[movedplace[0]],coorlisty[movedplace[1]]]
    if piecelist == [[coorlistx[0],coorlisty[0]],

        "!!"
        jump sudokuende
    jump sudokuauswertung

label mg_sudoku:
    scene su_bg
    show su_brett at Position(ypos = 740, xpos = 540)
    python:
        coorlistx = [184, 262, 340, 424, 502, 580, 663, 741, 819]
        coorlisty = [26, 104, 182, 266, 344, 422, 506, 584, 662]
        piecelist = [[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
        for i in range(81):
            x = renpy.random.randint(0, 200)
            y = renpy.random.randint(0, 700)
            piecelist[i] = [x,y]
        movedpiece = 0
        movedplace = [0, 0]
    jump sudokuauswertung
    
label sudokuende:
    scene black
    "you win"
    menu:
        "Play again?"
        
        "yes":
            jump mg_sudoku
            
        "no":
            return
I'd really appreciaty any help!
Thank you for your time. <3

- Ryouko
Attachments
sudokufield.png
The numbers of the empty fields.
Last edited by Endorphin on Fri Mar 02, 2012 10:01 am, edited 1 time in total.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#2 Post by KimiYoriBaka » Sun Feb 26, 2012 7:11 pm

you could add the number on each piece to the end of that piece's drag_name. that way you could then keep track of the numbers and check those as the victory condition instead.

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#3 Post by Endorphin » Mon Feb 27, 2012 1:47 am

Hmm... Yeah, that sounds logical, thank you. :>

So it would be "00 9" and "15 piece 9"?
(Or just "9" and "9")?
How do you get the last piece of the drag_name?

And the condition would be something like
if variable_that_stores_base_name == variable_that_stores_stone_name?

Thank you for your help! =)
I don't know what I'd do without you. x3

- R.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#4 Post by KimiYoriBaka » Mon Feb 27, 2012 9:48 am

Code: Select all

How do you get the last piece of the drag_name?
as seen by a programming language, a string is just a list/array of characters. thus, in python you access individual characters in the same way as a list. the first character is 0, then it goes up from there.

thus, for "00 9" it would be drag_name[3] (the space is included) and in "00 piece 9" it would be drag_name[9]. that said, since the final solution doesn't change, you don't really need to change to spots. only the pieces.

also, remember that you'll need to store it somewhere for for use it updating the the board, then again for use in checking for victory (because my code is inefficient like that). this means putting a line like this:

Code: Select all

store.movednum = drags[0].drag_name[9]
in your dragged function, then adjusting your main label (sudokuauswertung) to store it a list similar to piecelist when it places the pieces.

using the arbitrary name numlist, it would look something like this:

Code: Select all

    if ([coorlistx[movedplace[0]], coorlisty[movedplace[1]]] in piecelist):
        python:
            t1 = piecelist[movedpiece]
            t2 = piecelist.index([coorlistx[movedplace[0]], coorlisty[movedplace[1]]])
            tnum = numlist[piecelist.index([coorlistx[movedplace[0]], coorlisty[movedplace[1]]])]
            piecelist[movedpiece] = [coorlistx[movedplace[0]],coorlisty[movedplace[1]]]
            numlist[movedpiece] = movednum
            piecelist[t2] = t1
            numlist[t2] = tnum
    else:
        $ piecelist[movedpiece] = [coorlistx[movedplace[0]],coorlisty[movedplace[1]]]
        $ numlist[movedpiece = movednum
as for how to set up numlist, you just need a list with the same number of elements as you have pieces, probably with 0 in each space that doesn't start with a piece in it (it just needs to be a number you don't use elsewhere).

the victory condition just needs to check if numlist has the right numbers in it.

one last thing, for the pieces that start out on the board as part of the puzzle, make sure they're not draggable and that they have the right initial position.

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#5 Post by Endorphin » Mon Feb 27, 2012 1:13 pm

Ah, so that's how this works. *___*
(Didn't know you could actually tell Ren'Py which part of the string you want.)
Thank you for the information it'll come quite in handy in the future. x3
one last thing, for the pieces that start out on the board as part of the puzzle, make sure they're not draggable and that they have the right initial position.
At least that's nothing to worry about as these pieces are already on the board. =)
(I prefere this as I would probably mess it up any other way and only need this minigame once. x'D)

Code: Select all

as for how to set up numlist, you just need a list with the same number of elements as you have pieces, probably with 0 in each space that doesn't start with a piece in it (it just needs to be a number you don't use elsewhere).
This part confused me a little~
So it's basicly the same as the piecelist?
Like numlist= [[0, 0], [0,0]], or would it be like... numlist = [1, 9, 3, 5]?

Thank you for your patience and time, we're nearly there. :>

- R.
Attachments
Boden.png
The board.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#6 Post by KimiYoriBaka » Mon Feb 27, 2012 11:25 pm

Like numlist= [[0, 0], [0,0]], or would it be like... numlist = [1, 9, 3, 5]?
the second one. numlist just needs to have the numbers (or other symbols should you choose...), so it only needs to store one thing in each slot. the important thing is that it needs to be initialized with the same number of slots as the board has pieces, and that they contain the representative number for each piece that is already on the board, and an unused number for any spot that doesn't have a piece.

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#7 Post by Endorphin » Tue Feb 28, 2012 1:38 am

Ah, I see. :>
Thank you for explaining~
I'm sorry, but an uncaught exception occurred.

After loading the script.
KeyError: u'movedpiece ={color=#c00}\u2192{/color} movednum'
The only problem is that I keep getting this error. =/

Code: Select all

init python:
    
    def piece_dragged(drags, drop):
        
        if not drop:
            store.piecelist[(int(drags[0].drag_name[0]) * 10 + int(drags[0].drag_name[1]))][0] = drags[0].x
            store.piecelist[(int(drags[0].drag_name[0]) * 10 + int(drags[0].drag_name[1]))][1] = drags[0].y
            return
            
        store.movedpiece = int(drags[0].drag_name[0]) * 10 + int(drags[0].drag_name[1])
        store.movedplace = [int(drop.drag_name[0]), int(drop.drag_name[1])]
        store.movednum = drags[0].drag_name[9]
        
        return True

screen sudokusteine:
    
    draggroup:
        
        drag:
            drag_name "00"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[0]
            
        drag:
            drag_name "02"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[2]
         
        drag:
            drag_name "04"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[4]    
         
        drag:
            drag_name "05"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[5]    
            
        drag:
            drag_name "07"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[7]
            
        drag:
            drag_name "08"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[0] ypos coorlisty[8]    
            
        drag:
            drag_name "10"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[0]
            
        drag:
            drag_name "11"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[1]
        
        drag:
            drag_name "14"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[4]     
            
        drag:
            drag_name "15"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[5]    
        
        drag:
            drag_name "16"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[6]    
        
        drag:
            drag_name "17"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[7]    
            
        drag:
            drag_name "18"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[1] ypos coorlisty[8]    
            
        drag:
            drag_name "20"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[0]
            
        drag:
            drag_name "21"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[1]
            
        drag:
            drag_name "22"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[2]
            
        drag:
            drag_name "23"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[3]     
            
        drag:
            drag_name "26"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[6]      
         
        drag:
            drag_name "27"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[7]      
            
        drag:
            drag_name "28"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[2] ypos coorlisty[8]       
            
        drag:
            drag_name "30"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[0]
            
        drag:
            drag_name "31"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[1]
        
        drag:
            drag_name "32"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[2]
        
        drag:
            drag_name "33"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[3]    
            
        drag:
            drag_name "36"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[6]      
         
        drag:
            drag_name "37"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[7]      
            
        drag:
            drag_name "38"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[3] ypos coorlisty[8]  
                    
        drag:
            drag_name "41"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[1]
        
        drag:
            drag_name "45"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[5]      
            
        drag:
            drag_name "46"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[6]      
         
        drag:
            drag_name "47"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[4] ypos coorlisty[7]      
            
        drag:
            drag_name "51"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[1]
        
        drag:
            drag_name "52"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[2]
        
        drag:
            drag_name "53"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[3]    
            
        drag:
            drag_name "54"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[4]      
        
        drag:
            drag_name "55"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[5]      
        
        drag:
            drag_name "56"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[6]      
            
        drag:
            drag_name "57"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[5] ypos coorlisty[7]      
            
        drag:
            drag_name "61"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[1]
        
        drag:
            drag_name "65"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[5]
        
        drag:
            drag_name "67"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[7]    
            
        drag:
            drag_name "68"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[6] ypos coorlisty[8]     
        
        drag:
            drag_name "70"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[0]
        
        drag:
            drag_name "72"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[2]
        
        drag:
            drag_name "73"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[3]    
            
        drag:
            drag_name "74"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[4]     
        
        drag:
            drag_name "75"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[5]
            
        drag:
            drag_name "76"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[6]    
            
        drag:
            drag_name "77"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[7] ypos coorlisty[7] 
            
        drag:
            drag_name "80"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[0]
            
        drag:
            drag_name "81"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[1]
        
        drag:
            drag_name "83"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[3]  
            
        drag:
            drag_name "84"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[4]  
            
        drag:
            drag_name "85"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[5]      
            
        drag:
            drag_name "87"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[7]      
            
        drag:
            drag_name "88"
            child "Sudoku/Legestelle.png"
            draggable False
            xpos coorlistx[8] ypos coorlisty[8]  
            
#################################    
        
        drag:
            drag_name "00 piece 1"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[0][0] ypos piecelist[0][1]
            
        drag:
            drag_name "01 piece 1"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[1][0] ypos piecelist[1][1]
            
        drag:
            drag_name "02 piece 1"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[2][0] ypos piecelist[2][1]
            
        drag:
            drag_name "03 piece 1"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[3][0] ypos piecelist[3][1]
            
        drag:
            drag_name "07 piece 1"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[7][0] ypos piecelist[7][1]
            
        drag:
            drag_name "08 piece 1"
            child "Sudoku/1.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[8][0] ypos piecelist[8][1]
        ### 2  
        drag:
            drag_name "10 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[10][0] ypos piecelist[10][1]
            
        drag:
            drag_name "11 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[11][0] ypos piecelist[11][1]
            
        drag:
            drag_name "12 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[12][0] ypos piecelist[12][1]
            
        drag:
            drag_name "13 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[13][0] ypos piecelist[13][1]
            
        drag:
            drag_name "14 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[14][0] ypos piecelist[14][1]
            
        drag:
            drag_name "15 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[15][0] ypos piecelist[15][1]
            
        drag:
            drag_name "17 piece 2"
            child "Sudoku/2.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[17][0] ypos piecelist[17][1]
        ### 3    
        drag:
            drag_name "18 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[18][0] ypos piecelist[18][1]

        drag:
            drag_name "20 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[20][0] ypos piecelist[20][1]
            
        drag:
            drag_name "21 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[21][0] ypos piecelist[21][1]
            
        drag:
            drag_name "23 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[23][0] ypos piecelist[23][1]
            
        drag:
            drag_name "25 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[25][0] ypos piecelist[25][1]

        drag:
            drag_name "29 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[29][0] ypos piecelist[29][1]      
        
        drag:
            drag_name "30 piece 3"
            child "Sudoku/3.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[30][0] ypos piecelist[30][1]
        ### 4
        drag:
            drag_name "32 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[32][0] ypos piecelist[32][1]

        drag:
            drag_name "34 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[34][0] ypos piecelist[34][1]
            
        drag:
            drag_name "35 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[35][0] ypos piecelist[35][1]
            
        drag:
            drag_name "36 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[36][0] ypos piecelist[36][1]
            
        drag:
            drag_name "37 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[37][0] ypos piecelist[37][1]

        drag:
            drag_name "41 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[41][0] ypos piecelist[41][1]

        drag:
            drag_name "43 piece 4"
            child "Sudoku/4.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[43][0] ypos piecelist[43][1]
        ### 5    
        drag:
            drag_name "44 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[44][0] ypos piecelist[44][1]
            
        drag:
            drag_name "45 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[45][0] ypos piecelist[45][1]
            
        drag:
            drag_name "46 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[46][0] ypos piecelist[46][1]

        drag:
            drag_name "49 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[49][0] ypos piecelist[49][1]    
        
        drag:
            drag_name "50 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[50][0] ypos piecelist[50][1]        
            
        drag:
            drag_name "51 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[51][0] ypos piecelist[51][1]     
            
        drag:
            drag_name "52 piece 5"
            child "Sudoku/5.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[52][0] ypos piecelist[52][1]     
        ### 6
        drag:
            drag_name "53 piece 6"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[53][0] ypos piecelist[53][1]     
            
        drag:
            drag_name "55 piece 6"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[55][0] ypos piecelist[55][1] 
            
        drag:
            drag_name "56 piece 6"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[56][0] ypos piecelist[56][1]     
            
        drag:
            drag_name "57 piece 6"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[57][0] ypos piecelist[57][1]     
            
        drag:
            drag_name "58 piece 6"
            child "Sudoku/6.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[58][0] ypos piecelist[58][1]     
        ### 7 
        drag:
            drag_name "59 piece 7"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[59][0] ypos piecelist[59][1]     
            
        drag:
            drag_name "61 piece 7"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[61][0] ypos piecelist[61][1]     
         
        drag:
            drag_name "63 piece 7"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[63][0] ypos piecelist[63][1]      
            
        drag:
            drag_name "64 piece 7"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[64][0] ypos piecelist[64][1]      
            
        drag:
            drag_name "66 piece 7"
            child "Sudoku/7.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[66][0] ypos piecelist[66][1]   
        ### 8    
        drag:
            drag_name "67 piece 8"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[67][0] ypos piecelist[67][1]      
            
        drag:
            drag_name "68 piece 8"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[68][0] ypos piecelist[68][1]      
            
        drag:
            drag_name "69 piece 8"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[69][0] ypos piecelist[69][1]      
            
        drag:
            drag_name "70 piece 8"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[70][0] ypos piecelist[70][1]  
            
        drag:
            drag_name "71 piece 8"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[71][0] ypos piecelist[71][1]      
            
        drag:
            drag_name "72 piece 8"
            child "Sudoku/8.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[72][0] ypos piecelist[72][1]  
        ### 9    
        drag:
            drag_name "73 piece 9"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[73][0] ypos piecelist[73][1]      
            
        drag:
            drag_name "74 piece 9"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[74][0] ypos piecelist[74][1]      
            
        drag:
            drag_name "75 piece 9"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[75][0] ypos piecelist[75][1]      
            
        drag:
            drag_name "78 piece 9"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[78][0] ypos piecelist[78][1]      
        
        drag:
            drag_name "80 piece 9"
            child "Sudoku/9.png"
            droppable False
            dragged piece_dragged
            xpos piecelist[80][0] ypos piecelist[80][1]
            
label sudokuauswertung:
    call screen sudokusteine
    if ([coorlistx[movedplace[0]], coorlisty[movedplace[1]]] in piecelist):
        python:
            t1 = piecelist[movedpiece]
            t2 = piecelist.index([coorlistx[movedplace[0]], coorlisty[movedplace[1]]])
            tnum = numlist[piecelist.index([coorlistx[movedplace[0]], coorlisty[movedplace[1]]])]
            piecelist[movedpiece] = [coorlistx[movedplace[0]],coorlisty[movedplace[1]]]
            numlist[movedpiece] = movednum
            piecelist[t2] = t1
            numlist[t2] = tnum
    else:
        $ piecelist[movedpiece] = [coorlistx[movedplace[0]],coorlisty[movedplace[1]]]
        $ numlist[movedpiece = movednum]
    if piecelist == [[coorlistx[0],coorlisty[0]],
                        [coorlistx[1],coorlisty[0]],
                        [coorlistx[2],coorlisty[0]],
                        [coorlistx[3],coorlisty[0]],
                        [coorlistx[4],coorlisty[0]],
                        [coorlistx[5],coorlisty[0]],
                        [coorlistx[6],coorlisty[0]],
                        [coorlistx[7],coorlisty[0]],
                        [coorlistx[8],coorlisty[0]],
                        [coorlistx[0],coorlisty[1]],
                        [coorlistx[1],coorlisty[1]],
                        [coorlistx[2],coorlisty[1]],
                        [coorlistx[3],coorlisty[1]],
                        [coorlistx[4],coorlisty[1]],
                        [coorlistx[5],coorlisty[1]],
                        [coorlistx[6],coorlisty[1]],
                        [coorlistx[7],coorlisty[1]],
                        [coorlistx[8],coorlisty[1]],
                        [coorlistx[0],coorlisty[2]],
                        [coorlistx[1],coorlisty[2]],
                        [coorlistx[2],coorlisty[2]],
                        [coorlistx[3],coorlisty[2]],
                        [coorlistx[4],coorlisty[2]],
                        [coorlistx[5],coorlisty[2]],
                        [coorlistx[6],coorlisty[2]],
                        [coorlistx[7],coorlisty[2]],
                        [coorlistx[8],coorlisty[2]],
                        [coorlistx[0],coorlisty[3]],
                        [coorlistx[1],coorlisty[3]],
                        [coorlistx[2],coorlisty[3]],
                        [coorlistx[3],coorlisty[3]],
                        [coorlistx[4],coorlisty[3]],
                        [coorlistx[5],coorlisty[3]],
                        [coorlistx[6],coorlisty[3]],
                        [coorlistx[7],coorlisty[3]],
                        [coorlistx[8],coorlisty[3]],
                        [coorlistx[0],coorlisty[4]],
                        [coorlistx[1],coorlisty[4]],
                        [coorlistx[2],coorlisty[4]],
                        [coorlistx[3],coorlisty[4]],
                        [coorlistx[4],coorlisty[4]],
                        [coorlistx[5],coorlisty[4]],
                        [coorlistx[6],coorlisty[4]],
                        [coorlistx[7],coorlisty[4]],
                        [coorlistx[8],coorlisty[4]]]:
        "!!"
        jump sudokuende
    jump sudokuauswertung

label mg_sudoku:
    scene su_bg
    show su_brett at Position(ypos = 740, xpos = 540)
    python:
        coorlistx = [184, 262, 340, 424, 502, 580, 663, 741, 819]
        coorlisty = [26, 104, 182, 266, 344, 422, 506, 584, 662]
        piecelist = [[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
        numlist = [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        for i in range(81):
            x = renpy.random.randint(0, 200)
            y = renpy.random.randint(0, 700)
            piecelist[i] = [x,y]
        movedpiece = 0
        movedplace = [0, 0]
    jump sudokuauswertung
    
label sudokuende:
    scene black
    "you win"
    menu:
        "Play again?"
        
        "yes":
            jump mg_sudoku
            
        "no":
            return
Where did I go wrong? =o

- R.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#8 Post by KimiYoriBaka » Tue Feb 28, 2012 11:31 am

oh. looks like the code I posted had a typo. I should really check harder for those when posting...

Code: Select all

$ numlist[movedpiece = movednum]
this line has the closing bracket in the wrong spot. it should be

Code: Select all

$ numlist[movedpiece] = movednum
also, it just occurred to me while looking at your code that making those big list with all the zeros would probably be easier if you used a for loop then adjusted the ones that start with a value. sorry for not mentioning that earlier.

Code: Select all

numlist = []
for n in range(81):
    numlist.append(0)
numlist[0] = 3
in case you weren't aware, your numlist only has 56 spots.

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#9 Post by Endorphin » Tue Feb 28, 2012 3:16 pm

Nah, it's not your fault - typos like this happen all the time, and if I'd have a little more knowledge I'd have known where to put the bracelet.

Oh, thank you for telling me. :>
That nice to know~

Hmmm... How would you go on about the victory condition?
I'm kinda confused about that.
Do I need something like... eh... I don't know?
I thought that the number in the numlist were like the solving sheet, but I guess I was wrong there.

- R.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#10 Post by KimiYoriBaka » Tue Feb 28, 2012 11:41 pm

not sure what a solving sheet is. numlist would just be the list of what numbers/symbols you have in each spot. thus, to check for victory, you check if numlist has the right numbers in each spot.

the reason it's so different from what the code originally had, is because the original code assumed that piece list in arranged in a certain order that was easily comparable to coorlistx and coorlist y.

in this case though, you're not checking what order the pieces are in, but rather it's what each represents that important, so you need to check what's on the pieces instead, which is what numlist contains.

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#11 Post by Endorphin » Wed Feb 29, 2012 1:28 am

Ah, so I did understand it correctly. =o
But the problem is that I can't get it to work.
I wanted to have a simple winning condition first (as it takes pretty long to set the thing completly together) to try it out, but when entering

Code: Select all

numlist = []
for n in range(81):
    numlist.append(0)
numlist[0] = 3
the game isn't won when placing a 3 on the first (00) piece.
But that might be as the if-clause is still missing?
There's still just this one:

Code: Select all

if piecelist == [[coorlistx[0],coorlisty[0]],
                etc.
        jump sudokuende # victory
Does it need some kind "if numlist == whatever"?

- R.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#12 Post by KimiYoriBaka » Wed Feb 29, 2012 1:25 pm

oh, did you want that to be the victory condition? I had thought you wanted that to be the starting position of one of the 3's. You don't want to have that there at the start then.

numlist isn't where you should be storing your solution. the solution should only be in your if condition. numlist is supposed to keep track of the numbers currently on the board. the idea is that while piecelist keeps track of the exact individual pieces, numlist keeps track of only the numbers.

and yes, it does need "if numlist == whatever". the "whatever" is where you put the solution.

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#13 Post by Endorphin » Wed Feb 29, 2012 2:19 pm

I see, so we had a misunderstanding~ =)

So I need to remove something? =o
What exactly?
(I tried out the if-thingy but it kinda has no effect~)

I really appreciate your patience, thank you. x3

- R.
ImageImage
Image

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Problem with sudoku minigame

#14 Post by KimiYoriBaka » Fri Mar 02, 2012 2:40 am

no effect? that's not good...
(makes test program for code)

...oh. one moment.

(fiddles around with code)

right. my apologies for handing you code that doesn't work. I really need to think about my mental state before trying to help people, as I was clearly too tired to be thinking this hard when I posted earlier.

not your fault, my code was bad. as such, I'm just going to hand you some tested code, like I should've done from the start.

the lists are now arranged in a way that should be easier to read. I put the victory condition for numlist so that it's in 9 rows of 9, just like the actual board. just keep in mind while you're putting in the solution that the spots that already have pieces in them at the start should match the initial values for numlist (which can be done if you just leave them as 0's).

in case you're wondering, here's where I was wrong:
- numlist shouldn't be just a straight list of numbers. it should be an actual representation of the board (meaning it should at least handle x and y coordinates)

- numlist also isn't comparable to piecelist, so it shouldn't be handled as such (meaning my code for storing and switching numbers was completely wrong, hence why the if part didn't do anything)

- movednum needed to match the values of numlist, (meaning it needed to be converted after taking the characters from the drag_name)

one last thing, the attached code does work, but there's one inherent flaw caused by deriving it from my previous code. That is, it doesn't have any way to adjust the values of numlist if the player places a piece off to the side. This means that if a player places a piece into a correct spot and removes it, the game think the piece is still there until another one is placed. Thus, it is possible (though highly unlikely) that a player could win while one or two pieces aren't in place.

to deal with that, I put in code that might solve it by requiring that every space be filled. it's currently commented out, but once you're ready to test out your full solution, you should see if it works. If it doesn't, just delete it.
Attachments
sudoku.rpy
(24.69 KiB) Downloaded 86 times

User avatar
Endorphin
Veteran
Posts: 366
Joined: Mon Nov 22, 2010 10:52 am
Projects: 1plus3
Location: Germany
Contact:

Re: Problem with sudoku minigame

#15 Post by Endorphin » Fri Mar 02, 2012 10:01 am

Please don't blame yourself! ó__ò
Now that I think about it, I should have given you the project so that you wouldn't have to make the dummies for yourself - I figure that this was quite annoying.

But now...
THANK YOU! :>
It works perfectly. <3
(I can live with this little bug for now, might try to make this work later.)
Thanks to you I have this cute minigame in my VN. =w=
I also really appreciate your patience - I'm so slow sometimes but you still helped me out till the end.
So thank you for this. :>
I learned a lot on the way~

- R.
ImageImage
Image

Post Reply

Who is online

Users browsing this forum: No registered users