Example #1
0
void			ldi(t_vm *vm, t_process *proc)
{
	t_instruction	*instr;
	t_arg_type		type[2];
	int				ops[2];
	int				data;
	size_t			reg;

	instr = &proc->instruction;
	reg = instr->params[2];
	type[0] = instr->args_types[0];
	type[1] = instr->args_types[1];
	if (check_param(instr->args_types[2], reg)
		&& check_param(type[0], instr->params[0])
		&& check_param(type[1], instr->params[1]))
	{
		ops[0] = get_value(type[0], instr->params[0], &vm->arena, proc);
		ops[1] = get_value(type[1], instr->params[1], &vm->arena, proc);
		data = loadmem(&vm->arena, REG_SIZE,
						proc->pc + (ops[0] + ops[1]) % IDX_MOD);
		ltob(&data, REG_SIZE);
		storeg(&proc->registers[reg], &data, REG_SIZE);
	}
	move_pc(&proc->pc, instr->size);
}
Example #2
0
int read_movelines (char txt[128], int verbose) {
    char *movement = strtok(txt, " ");
    struct move move;
    int x=0;

    //movement = strtok(NULL, " "); 

        while ( movement != NULL) {

            if (parse_move(&move, movement, 1-machineplays)) {
                Vb printf("moving from input: %i%i %i%i\n",move.from[0],move.from[1],move.to[0],move.to[1]);
                move.casualty = board.squares[move.to[0]][move.to[1]]; 
                
                move_pc(&board, &move);

                history_append(&move);
                x++;
            }
        movement = strtok(NULL, " ");        
                
        }
    Vb printf("%i moves read.\n",x);

    
    
    return x;
}
Example #3
0
 JNIEXPORT void JNICALL
   Java_com_example_hellojni_HelloJni_handleInputStairsDown
   (JNIEnv *env, jobject obj)
   {
      d.max_monsters = 5;
      d.combat_message = "";
      move_pc(dungeon_UI::instance()->get_dungeon(), '>');
      dungeon_UI::instance()->gen_character_map();
   }
Example #4
0
void		and_(t_vm *vm, t_process *proc)
{
	t_instruction	*instr;
	int				p0;
	int				p1;
	int				p2;
	int				res;

	(void)vm;
	instr = &proc->instruction;
	p0 = instr->params[0];
	p1 = instr->params[1];
	p2 = instr->params[2];
	if (check_param(instr->args_types[0], p0)
		&& check_param(instr->args_types[1], p1)
		&& check_param(instr->args_types[2], p2))
	{
		res = get_value(instr->args_types[0], p0, &vm->arena, proc);
		res &= get_value(instr->args_types[1], p1, &vm->arena, proc);
		storeg(&proc->registers[p2], &res, sizeof(res));
		proc->carry = (res == 0);
	}
	move_pc(&proc->pc, instr->size);
}
Example #5
0
void io_handle_input(dungeon_t *d)
{
  uint32_t fail_code;
  int key;

  do {
    switch (key = getch()) {
    case '7':
    case 'y':
    case KEY_HOME:
      fail_code = move_pc(d, 7);
      break;
    case '8':
    case 'k':
    case KEY_UP:
      fail_code = move_pc(d, 8);
      break;
    case '9':
    case 'u':
    case KEY_PPAGE:
      fail_code = move_pc(d, 9);
      break;
    case '6':
    case 'l':
    case KEY_RIGHT:
      fail_code = move_pc(d, 6);
      break;
    case '3':
    case 'n':
    case KEY_NPAGE:
      fail_code = move_pc(d, 3);
      break;
    case '2':
    case 'j':
    case KEY_DOWN:
      fail_code = move_pc(d, 2);
      break;
    case '1':
    case 'b':
    case KEY_END:
      fail_code = move_pc(d, 1);
      break;
    case '4':
    case 'h':
    case KEY_LEFT:
      fail_code = move_pc(d, 4);
      break;
    case '5':
    case ' ':
    case KEY_B2:
      fail_code = 0;
      break;
    case '>':
      fail_code = move_pc(d, '>');
      break;
    case '<':
      fail_code = move_pc(d, '<');
      break;
    case 'S':
      d->save_and_exit = 1;
      character_reset_turn(d->pc);
      fail_code = 0;
      break;
    case 'Q':
      /* Extra command, not in the spec.  Quit without saving.          */
      d->quit_no_save = 1;
      fail_code = 0;
      break;
    case 'T':
      /* New command.  Display the distances for tunnelers.             */
      io_display_tunnel(d);
      fail_code = 1;
      break;
    case 'D':
      /* New command.  Display the distances for non-tunnelers.         */
      io_display_distance(d);
      fail_code = 1;
      break;
    case 'H':
      /* New command.  Display the hardnesses.                          */
      io_display_hardness(d);
      fail_code = 1;
      break;
    case 's':
      /* New command.  Return to normal display after displaying some   *
       * special screen.                                                */
      io_display(d);
      fail_code = 1;
      break;
    case 'g':
      /* Teleport the PC to a random place in the dungeon.              */
      io_teleport_pc(d);
      fail_code = 0;
      break;
    case 'm':
      io_list_monsters(d);
      fail_code = 1;
      break;
    case 'a':
      io_display_all(d);
      fail_code = 1;
      break;
    case 'q':
      /* Demonstrate use of the message queue.  You can use this for *
       * printf()-style debugging (though gdb is probably a better   *
       * option.  Not that it matterrs, but using this command will  *
       * waste a turn.  Set fail_code to 1 and you should be able to *
       * figure out why I did it that way.                           */
      io_queue_message("This is the first message.");
      io_queue_message("Since there are multiple messages, "
                       "you will see \"more\" prompts.");
      io_queue_message("You can use any key to advance through messages.");
      io_queue_message("Normal gameplay will not resume until the queue "
                       "is empty.");
      io_queue_message("Long lines will be truncated, not wrapped.");
      io_queue_message("io_queue_message() is variadic and handles "
                       "all printf() conversion specifiers.");
      io_queue_message("Did you see %s?", "what I did there");
      io_queue_message("When the last message is displayed, there will "
                       "be no \"more\" prompt.");
      io_queue_message("Have fun!  And happy printing!");
      fail_code = 0;
      break;
    default:
      /* Also not in the spec.  It's not always easy to figure out what *
       * key code corresponds with a given keystroke.  Print out any    *
       * unhandled key here.  Not only does it give a visual error      *
       * indicator, but it also gives an integer value that can be used *
       * for that key in this (or other) switch statements.  Printed in *
       * octal, with the leading zero, because ncurses.h lists codes in *
       * octal, thus allowing us to do reverse lookups.  If a key has a *
       * name defined in the header, you can use the name here, else    *
       * you can directly use the octal value.                          */
      mvprintw(0, 0, "Unbound key: %#o ", key);
      fail_code = 1;
    }
  } while (fail_code);
}
Example #6
0
 JNIEXPORT void JNICALL
   Java_com_example_hellojni_HelloJni_handleInput9
   (JNIEnv *env, jobject obj)
   {
      move_pc(dungeon_UI::instance()->get_dungeon(), 9);
   }
Example #7
0
Device long thinkiterate_fast(struct board *_board, int DEEP, int verbose,
				  long Alpha, long Beta, int AllowCutoff) {

  int i=0, r=0, PersistentBufferOnline=0;
    
  int enemy_score=0, machine_score=0;

  int ABcutoff = 0;


    
  long score=-INFINITE;

  struct movelist moves;

  int PLAYER =  _board->whoplays;
    
  legal_moves(_board, &moves, PLAYER, 0);
  searchNODEcount++;
    
  //If in checkmate/stalemate situation;
  if (!moves.k) {
             
    if (ifsquare_attacked(_board->squares,
			  findking(_board->squares, 'Y', PLAYER), 
			  findking(_board->squares, 'X', PLAYER),
			  PLAYER, 0)) {
      score = -13000 + 50*(BRAIN.DEEP-DEEP);
      //if (PLAYER != Machineplays) flip(score);
    }
       
    else score = 0; 

    return score;
         
  }
    


  //IFnotGPU( Vb show_board(_board->squares); )
  if (DEEP>0) {

    reorder_movelist(&moves); 
    
    //NULL MOVE: guaranteed as long as if PL is not in check,
    //and its not K+P endgame.
    //if(DEEP > BRAIN.DEEP - 2) 
      /*      if(canNullMove(DEEP, _board, moves.k, PLAYER)) {
	flip(_board->whoplays);
	DisposableBuffer = thinkiterate(_board, DEEP-1, verbose,
					-Beta, -Alpha, AllowCutoff);
	invert(DisposableBuffer->score);
	flip(_board->whoplays);
	if (DisposableBuffer->score > Alpha)
	  Alpha = DisposableBuffer->score;

	DUMP(DisposableBuffer);
	}*/
     


    // Movelist iteration.
    for(i=0;i<moves.k;i++) {
       
      move_pc(_board, &moves.movements[i]);  

      moves.movements[i].score = -thinkiterate_fast(_board, DEEP-1, verbose,
						    -Beta, -Alpha, AllowCutoff);

      
	if (moves.movements[i].score > score) 
	  score = moves.movements[i].score;

	if (moves.movements[i].score > Alpha) 
	  Alpha = moves.movements[i].score;
      
      undo_move(_board, &moves.movements[i]);
      
	if (Beta<=Alpha && AllowCutoff) 
	  break;       
       
    }

    return score;
    
  }
     
  else {

    machine_score = evaluate(_board, &moves, PLAYER, PLAYER);
    enemy_score = evaluate(_board, &moves, 1-PLAYER, PLAYER) * ( 1+BRAIN.presumeOPPaggro);

    score = machine_score - enemy_score;
    //if (PLAYER != Machineplays) invert(score);

    return score;
  }

}
Example #8
0
int think_fast(struct move *out, int PL, int DEEP, int verbose) {
    
  int i=0; int ChosenMovementIndex=0;
  long score = -INFINITE;

  time_t startT = time(NULL);
  
  searchNODEcount = 0;
  
  struct board *_board = makeparallelboard(&board);
  _board->MovementCount=0;
  int CurrentMovementIndex = _board->MovementCount;

  
  long Alpha = -INFINITE;
  long Beta = INFINITE;
  
  struct movelist *moves =
    (struct movelist *) calloc(1, sizeof(struct movelist));
  
  int PLAYER = Machineplays;
  legal_moves(_board, moves, PLAYER, 0);
  
  if (board.MovementCount == 0) { //primitive opening book:
    int moveBook[4] = {9, //e2e4
		       7, //d2d4
		       19, //g1f3
		       5,}; //c2c4
      
    srand ( rndseed() );
    ChosenMovementIndex = moveBook[rand() % 4];


    replicate_move(out, &moves->movements[ChosenMovementIndex]);
      
    DUMP(moves);
    DUMP(_board);
    return ChosenMovementIndex;
		       
  }
  
  reorder_movelist(moves);

  if (moves->k == 0) {
    DUMP(_board);
    DUMP(moves);
    return -1;
  }

  int AllowCutoff = 1;
 
  
  /* if(canNullMove(DEEP, _board, moves->k, PLAYER)) {
    flip(_board->whoplays);
    BufferBoard = thinkiterate(_board, DEEP-1, verbose, -Beta, -Alpha, AllowCutoff);
    flip(_board->whoplays);
    invert(BufferBoard->score);
    if (BufferBoard->score > Alpha) Alpha = BufferBoard->score;

    DUMP(BufferBoard)
    }*/
    

  for (i=0;i<moves->k;i++) {

    move_pc(_board, &moves->movements[i]);    
    moves->movements[i].score = -thinkiterate_fast(_board, DEEP-1, verbose,
			       -Beta, -Alpha, AllowCutoff);      



    if (moves->movements[i].score > score) {
      score = moves->movements[i].score;
      ChosenMovementIndex=i;
    }
    if (moves->movements[i].score > Alpha)      Alpha = moves->movements[i].score;

    undo_move(_board, &moves->movements[i]);
  }     
             
  replicate_move(out, &moves->movements[ChosenMovementIndex]);
  
  return ChosenMovementIndex;
   
}