// File: matallui[P]nibble-curses/src/CNibbles.cpp
// Function: CNibbles::Step()
bool CNibbles::Step ( void )
{
  if ( m_nplayers == 1)
  {
    // move snake
    m_snakes[0]->Move();
    // check collisions
    if ( m_snakes[0]->Collision ( m_obstacles, m_num_obstacles, NULL ) )
    {
      m_score -= 1000;
      UpdateScores();
      if ( m_snakes[0]->getLives() > 0 ) 	
      {
	m_state = 1;	// restart level
	PlayerDies(1);
      }
      else					m_state = 3;	// game over
      return false;
    }
    // check if eats food
    if ( m_snakes[0]->Eat ( m_xyfood, m_nfood, m_level ) )
    {
      m_score += (100*m_level + 100*m_nfood);
      m_nfood ++;
      UpdateScores();
      if ( m_nfood == 10 )
      {
	m_state = 2;	// Next Level
	return false;
      }
      PutFood();
    }
  }
  else
  {
    // move snakes
    if ( ! m_snakes[0]->Move() )	throw CException( "Problems with communication." );
    if ( ! m_snakes[1]->Move() )	throw CException( "Problems with communication." );
    
    // check for collisions
    if ( m_snakes[0]->Collision ( m_obstacles, m_num_obstacles, m_snakes[1] ) )
    {
      m_score -= 1000;
      UpdateScores();
      if ( m_snakes[0]->getLives() > 0 || m_snakes[1]->getLives() > 0 )
      {
	m_state = 1;
	PlayerDies(1);
      }
      else	m_state = 3;
      return false;
    }
    else if ( m_snakes[1]->Collision ( m_obstacles, m_num_obstacles, m_snakes[0] ) )
    {
      m_score -= 1000;
      UpdateScores();
      if ( m_snakes[0]->getLives() > 0 || m_snakes[1]->getLives() > 0 )
      {
	m_state = 1;
	PlayerDies(2);
      }
      else	m_state = 3;
      return false;
    }
    // check if someone eats food
    if ( m_snakes[0]->Eat ( m_xyfood, m_nfood, m_level ) || m_snakes[1]->Eat ( m_xyfood, m_nfood, m_level ) )
    {
      m_score += (100*m_level + 100*m_nfood);
      m_nfood ++;
      UpdateScores();
      if ( m_nfood == 10 )
      {
	m_state = 2;
	return false;
      }
      PutFood();
    } 
  }

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpl $0x1, 0x10(%rax)
jne 0x8a98
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq -0x88(%rbp), %rdx
movq 0x30(%rdx), %rax
movq (%rax), %rdi
movq 0x28(%rdx), %rsi
addq $0xc, %rdx
movq (%rdi), %rax
xorl %ecx, %ecx
callq *0x20(%rax)
testb $0x1, %al
jne 0x89ac
jmp 0x8a12
movq -0x88(%rbp), %rdi
movl 0x20(%rdi), %eax
subl $0x3e8, %eax            # imm = 0x3E8
movl %eax, 0x20(%rdi)
callq 0xb620
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
callq 0x45a0
cmpl $0x0, %eax
jle 0x89fb
movq -0x88(%rbp), %rdi
movl $0x1, 0x24(%rdi)
movl $0x1, -0x14(%rbp)
leaq -0x14(%rbp), %rsi
callq 0xaea0
jmp 0x8a09
movq -0x88(%rbp), %rax
movl $0x3, 0x24(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x8e4a
movq -0x88(%rbp), %rcx
movq 0x30(%rcx), %rax
movq (%rax), %rdi
movq %rcx, %rsi
addq $0x38, %rsi
movq %rcx, %rdx
addq $0x40, %rdx
addq $0x8, %rcx
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x8a3e
jmp 0x8a93
movq -0x88(%rbp), %rdi
imull $0x64, 0x8(%rdi), %eax
imull $0x64, 0x40(%rdi), %ecx
addl %ecx, %eax
addl 0x20(%rdi), %eax
movl %eax, 0x20(%rdi)
movl 0x40(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x40(%rdi)
callq 0xb620
movq -0x88(%rbp), %rax
cmpl $0xa, 0x40(%rax)
jne 0x8a87
movq -0x88(%rbp), %rax
movl $0x2, 0x24(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x8e4a
movq -0x88(%rbp), %rdi
callq 0xb730
jmp 0x8e46
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testb $0x1, %al
jne 0x8b6c
movb $0x1, -0x4d(%rbp)
movl $0x20, %edi
callq 0x31a0
movq %rax, -0x98(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x34f0
movq -0x90(%rbp), %rdx
leaq 0x3a34(%rip), %rsi      # 0xc51b
leaq -0x38(%rbp), %rdi
callq 0x3880
jmp 0x8af2
movq -0x98(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3770
jmp 0x8b04
movq -0x98(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0x725a(%rip), %rsi      # 0xfd70
leaq 0x3113(%rip), %rdx      # 0xbc30
callq 0x34d0
jmp 0x8e61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8b4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31d0
leaq -0x39(%rbp), %rdi
callq 0x3340
testb $0x1, -0x4d(%rbp)
jne 0x8b5b
jmp 0x8b67
movq -0x98(%rbp), %rdi
callq 0x3220
jmp 0x8e58
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
testb $0x1, %al
jne 0x8c41
movb $0x1, -0x72(%rbp)
movl $0x20, %edi
callq 0x31a0
movq %rax, -0xa8(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x34f0
movq -0xa0(%rbp), %rdx
leaq 0x395f(%rip), %rsi      # 0xc51b
leaq -0x70(%rbp), %rdi
callq 0x3880
jmp 0x8bc7
movq -0xa8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3770
jmp 0x8bd9
movq -0xa8(%rbp), %rdi
movb $0x0, -0x72(%rbp)
leaq 0x7185(%rip), %rsi      # 0xfd70
leaq 0x303e(%rip), %rdx      # 0xbc30
callq 0x34d0
jmp 0x8e61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x8c1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x31d0
leaq -0x71(%rbp), %rdi
callq 0x3340
testb $0x1, -0x72(%rbp)
jne 0x8c30
jmp 0x8c3c
movq -0xa8(%rbp), %rdi
callq 0x3220
jmp 0x8e58
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rdi
movq 0x28(%rax), %rsi
movq %rax, %rdx
addq $0xc, %rdx
movq 0x30(%rax), %rax
movq 0x8(%rax), %rcx
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0x8c6e
jmp 0x8ced
movq -0x88(%rbp), %rdi
movl 0x20(%rdi), %eax
subl $0x3e8, %eax            # imm = 0x3E8
movl %eax, 0x20(%rdi)
callq 0xb620
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
callq 0x45a0
cmpl $0x0, %eax
jg 0x8cb6
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x45a0
cmpl $0x0, %eax
jle 0x8cd6
movq -0x88(%rbp), %rdi
movl $0x1, 0x24(%rdi)
movl $0x1, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0xaea0
jmp 0x8ce4
movq -0x88(%rbp), %rax
movl $0x3, 0x24(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x8e4a
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rcx
movq 0x8(%rcx), %rdi
movq 0x28(%rax), %rsi
movq %rax, %rdx
addq $0xc, %rdx
movq 0x30(%rax), %rax
movq (%rax), %rcx
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0x8d1a
jmp 0x8d99
movq -0x88(%rbp), %rdi
movl 0x20(%rdi), %eax
subl $0x3e8, %eax            # imm = 0x3E8
movl %eax, 0x20(%rdi)
callq 0xb620
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rdi
callq 0x45a0
cmpl $0x0, %eax
jg 0x8d62
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x45a0
cmpl $0x0, %eax
jle 0x8d82
movq -0x88(%rbp), %rdi
movl $0x1, 0x24(%rdi)
movl $0x2, -0x7c(%rbp)
leaq -0x7c(%rbp), %rsi
callq 0xaea0
jmp 0x8d90
movq -0x88(%rbp), %rax
movl $0x3, 0x24(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x8e4a
jmp 0x8d9b
movq -0x88(%rbp), %rcx
movq 0x30(%rcx), %rax
movq (%rax), %rdi
movq %rcx, %rsi
addq $0x38, %rsi
movq %rcx, %rdx
addq $0x40, %rdx
addq $0x8, %rcx
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x8df2
movq -0x88(%rbp), %rcx
movq 0x30(%rcx), %rax
movq 0x8(%rax), %rdi
movq %rcx, %rsi
addq $0x38, %rsi
movq %rcx, %rdx
addq $0x40, %rdx
addq $0x8, %rcx
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x8df2
jmp 0x8e44
movq -0x88(%rbp), %rdi
imull $0x64, 0x8(%rdi), %eax
imull $0x64, 0x40(%rdi), %ecx
addl %ecx, %eax
addl 0x20(%rdi), %eax
movl %eax, 0x20(%rdi)
movl 0x40(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x40(%rdi)
callq 0xb620
movq -0x88(%rbp), %rax
cmpl $0xa, 0x40(%rax)
jne 0x8e38
movq -0x88(%rbp), %rax
movl $0x2, 0x24(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x8e4a
movq -0x88(%rbp), %rdi
callq 0xb730
jmp 0x8e46
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xb0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x34e0
nopw %cs:(%rax,%rax)