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

Pages: 1-

Fun /prog/ Activity

Name: Anonymous 2010-06-06 5:18

Read these three code excerpts and attempt a guess at what the full program is designed to do. I do not intend to reveal the nature of the program, because I have great confidence that after a bit of discussion /prog/ will inevitably come to the right conclusion.

Segment 1:
for(i = 0; i < gridSize; i++)
        {
            for(j = 0; j < gridSize; j++)
            {
                for(k = 0; k < 6; k++)
                {
                    if(k < 5)
                        bufferGraphics.drawLine((int)testHex[i][j].xPoints[k], (int)testHex[i][j].yPoints[k], (int)testHex[i][j].xPoints[k+1], (int)testHex[i][j].yPoints[k+1]);
                    else
                        bufferGraphics.drawLine((int)testHex[i][j].xPoints[k], (int)testHex[i][j].yPoints[k], (int)testHex[i][j].xPoints[0], (int)testHex[i][j].yPoints[0]);
                }
            }
        }


Segment 2:
if(mouseY > testHex[i][j].yPoints[1] && mouseY < testHex[i][j].yPoints[2])
                {
                    vector = (mouseY - testHex[i][j].yPoints[5])/(Math.sin(300*Math.PI/180));
                    xTest1 = testHex[i][j].xPoints[5] + vector*Math.cos(300*Math.PI/180);
                    vector = (mouseY - testHex[i][j].yPoints[1])/(Math.sin(60*Math.PI/180));
                    xTest2 = testHex[i][j].xPoints[1] + vector*Math.cos(60*Math.PI/180);
                   
                    if(mouseX > xTest1 && mouseX < xTest2)
                    {
                        detected(i, j);
                    }
                }
                if(mouseY > testHex[i][j].yPoints[2] && mouseY < testHex[i][j].yPoints[3])
                {
                    vector = (mouseY - testHex[i][j].yPoints[4])/(Math.sin(240*Math.PI/180));
                    xTest1 = testHex[i][j].xPoints[4] + vector*Math.cos(240*Math.PI/180);
                    vector = (mouseY - testHex[i][j].yPoints[2])/(Math.sin(120*Math.PI/180));
                    xTest2 = testHex[i][j].xPoints[2] + vector*Math.cos(120*Math.PI/180);
                   
                    if(mouseX > xTest1 && mouseX < xTest2)
                    {
                        detected(i, j);
                    }
                }


Segment 3:
public hex(hex Copy)
    {
        iIndex = Copy.iIndex;
        jIndex = Copy.jIndex;
        threatLevel = Copy.threatLevel;
        hexSize = Copy.hexSize;
        terrain = Copy.terrain;
        currentVPBuffer = Copy.currentVPBuffer;
        victoryPoints = Copy.victoryPoints;
        defLevel = Copy.defLevel;
        defPoints = Copy.defPoints;
        heldBy = Copy.heldBy;
        NPC = Copy.NPC;
        this.setLocation(Copy.yPoints[0], Copy.xPoints[0], Copy.hexSize);
    }

Name: Anonymous 2010-06-06 5:25

Name: Anonymous 2010-06-06 5:36

>>2
Its not the same thing. This program is not something found anywhere on the internet but here. Instead of attempting to recognize it, you read the code for the first time and attempt to figure out what it does.

Name: Anonymous 2010-06-06 5:42











































1. MOTHERFUCKER
2. MOTHERFUCKER
3. MOTHERFUCKER

Name: Anonymous 2010-06-06 5:47

>>3
My apologies, then.

Name: Anonymous 2010-06-06 6:18

I think segment involves some kind of lines being drawn

Name: Anonymous 2010-06-06 6:21

Segment 1 is just drawing 6 lines over and over again. The array is named "testHex" so I'm guessing each of those 6 lines is a single hexagon.

Name: Anonymous 2010-06-06 6:23

ZOMG IS IT DRAWING THE BLOCKBUSTERS GAME BOARD?

Name: Anonymous 2010-06-06 6:31

OP, why don't you just do
  for(k = 0; k < 6; k++)
                {
                    bufferGraphics.drawLine((int)testHex[i][j].xPoints[k], (int)testHex[i][j].yPoints[k], (int)testHex[i][j].xPoints[k], (int)testHex[i][j].yPoints[k]);
                }

Name: Anonymous 2010-06-06 6:55

1. Drawing a hexagon
2. Inefficient point-shape collision detection
3. Duplicating a Hex.
It appears to be a turn-based strategy game or whatever.

OP, if you want to challenge us, please do it with some at least slightly obfuscated code or in a language that doesn't immediately spell out its intention on every line.
If you don't, that's fine.

Name: level 2 2010-06-06 11:03


[bits 16]
[org 0x100]
; %define VAL1 ???
; %define VAL2 ???

; ...

; On entry:
;   Args:
;   ax = 0 or 1
;   dx = 0 or 1
;   [ds:bx] = char*
   
;   Returns:
;   ax = char*
   
    start:
        push si            
        push di            
        push ax
        neg  ax
        mov  si, ax
        shl  ax, 1
        inc  ax
        mov  di, ax
        pop  ax
        xor  ax, dx
        jnz  .baab0
        jmp  .abba0
       
    .abba1:
        add  bx, di
    .abba0:
        mov  al, [bx+si]
        cmp  al, VAL1
        je   .abba1
        cmp  al, VAL2
        je   .abba1
        jmp  .abba2
   
    .abba2:
        add  bx, di
        mov  al, [bx+si]
        cmp  al, VAL1
        je   .return
        cmp  al, VAL2
        je   .return
        jmp  .abba2
       
    .baab1:
        add  bx, di
    .baab0:
        mov  al, [bx+si]
        cmp  al, VAL1
        je   .baab2
        cmp  al, VAL2
        je   .baab2
        jmp  .baab1
   
    .baab2:
        add  bx, di
        mov  al, [bx+si]
        cmp  al, VAL1
        je   .baab2
        cmp  al, VAL2
        je   .baab2
        jmp  .return
       
    .return:
        mov  ax, bx
        pop  di
        pop  si
        retn


What does it do, and what are val1 and val2 most likely to be?

Name: Anonymous 2010-06-06 11:05

bleh start should be func_start

Name: Anonymous 2010-06-06 14:13

>>10
Why inefficient?

>>9
Because that would just draw six dots.

Name: Anonymous 2010-06-06 14:20

>>10
It's doing up to 8 trigonometry functions, and there's just a lot of stuff going on. Just figure out how far from the nearest edge the mouse is, vectors don't need any trigonometry.

Name: Anonymous 2010-06-06 14:28

>>14
Well, I'll try to rethink it, but that's the easiest way I can think to detect if a point is inside a hexagon. Also, sine and cosine aren't really that time consuming to perform.

Name: >>9 2010-06-06 14:39

>>13
Yeah, that was a transcription error on my part.

Name: Anonymous 2010-06-06 14:56

>>11
car and cdr

Name: Anonymous 2010-06-06 16:06

>>15
You want to test if a point is inside a convex polygon. For each edge of the polygon (going counter clockwise), use the perp dot product to determine if the point lies "to the right" of that edge. If the point lies to the right of any edge, then the point is not inside the polygon. Otherwise, the point lies to the left of all edges, and is inside the polygon.

Name: Anonymous 2010-06-06 16:13

>>18
You can also safely return true prematurely if the line through the centre of the shape and the point intersects an edge, as well as the point being 'to the left'.

There are countless optimisations to be done. Metanet have excellent tutorials on exactly this.

Name: Anonymous 2010-06-06 17:49

>>18
Ok, maybe I'm not understanding something here. What if the point was outside just to the left of the entire polygon? Wouldnt that still be detected as "inside"?

Name: Anonymous 2010-06-06 17:52

>>20
Imagine you're walking along the edges, anti-clockwise. Your left hand is inside the shape, and your right is outside.

Name: Anonymous 2010-06-06 17:59

>>21
ahh, OK I get it. I have yet to learn to use dot products or most vector operations for that matter. Seeing as how I'm working on graphical applications now I should probably learn.

Name: Anonymous 2010-06-06 19:41

>>22
Watch the MIT video lectures on multi-variable calculus.

Name: Anonymous 2011-02-04 18:39

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