Esempio n. 1
0
 int main()
// todo command line arguments
 { int fd1;
   char buf[1000];
   setup_stdin();
   fd1=init();
//todo make sure fd1 is ok
   if(fork()) from_to(fd1,1);
   else from_to(0,fd1);

   //todo sure would be nice to have an exit condition
     return 1;

 }
Esempio n. 2
0
void MovePicker::score() {

  static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");

  for (auto& m : *this)
      if (Type == CAPTURES)
      {
#ifdef ATOMIC
          if (pos.is_atomic())
              m.value = pos.see<ATOMIC_VARIANT>(m);
          else
#endif
#ifdef RACE
          if (pos.is_race())
              m.value =  PieceValue[pos.variant()][MG][pos.piece_on(to_sq(m))]
                       - Value(200 * relative_rank(BLACK, to_sq(m)))
                       + (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))] / 8;
          else
#endif
          m.value =  PieceValue[pos.variant()][MG][pos.piece_on(to_sq(m))]
                   + (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))] / 8;
      }
      else if (Type == QUIETS)
      {
          m.value =  (*mainHistory)[pos.side_to_move()][from_to(m)]
                   + (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
                   + (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
                   + (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)];
#ifdef ANTI
          if (pos.is_anti() && pos.attackers_to(to_sq(m), pos.pieces() ^ from_sq(m)) & pos.pieces(~pos.side_to_move()))
          {
              m.value += (1 << 28);
              if (!(pos.attackers_to(from_sq(m)) & pos.pieces(~pos.side_to_move())))
                  m.value += (1 << 27);
          }
#endif
      }
      else // Type == EVASIONS
      {
          if (pos.capture(m))
              m.value =  PieceValue[pos.variant()][MG][pos.piece_on(to_sq(m))]
                       - Value(type_of(pos.moved_piece(m)));
          else
              m.value =  (*mainHistory)[pos.side_to_move()][from_to(m)]
                       + (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
                       - (1 << 28);
      }
}
Esempio n. 3
0
void MovePicker::score<EVASIONS>()
{
	const ButterflyHistory& history = pos.this_thread()->history;
	Color c = pos.side_to_move();

	for (auto& m : *this)

		// 駒を取る指し手ならseeがプラスだったということなのでプラスの符号になるようにStats::Maxを足す。
		// あとは取る駒の価値を足して、動かす駒の番号を引いておく(小さな価値の駒で王手を回避したほうが
		// 価値が高いので(例えば合駒に安い駒を使う的な…)

		//  ・成るなら、その成りの価値を加算したほうが見積もりとしては正しい?
		//  それは取り返されないことが前提にあるから、そうでもない。
		//		T1,r300,2491 - 78 - 2421(50.71% R4.95)
		//		T1,b1000,2483 - 103 - 2404(50.81% R5.62)
		//      T1,b3000,2459 - 148 - 2383(50.78% R5.45)
		//   → やはり、改造前のほうが良い。[2016/10/06]

		// ・moved_piece_before()とmoved_piece_after()との比較
		//  厳密なLVAではなくなるが、afterのほうが良さげ。
		//  例えば、歩を成って取るのと、桂で取るのとでは、安い駒は歩だが、桂で行ったほうが、
		//  歩はあとで成れるとすれば潜在的な価値はそちらのほうが高いから、そちらを残しておくという理屈はあるのか。
		//		T1, b1000, 2402 - 138 - 2460(49.4% R - 4.14) win black : white = 51.04% : 48.96%
		//		T1,b3000,1241 - 108 - 1231(50.2% R1.41) win black : white = 50.53% : 49.47%
		//		T1,b5000,1095 - 118 - 1047(51.12% R7.79) win black : white = 52.33% : 47.67%
		//  → moved_piece_before()のほうで問題なさげ。[2017/5/20]

		if (pos.capture(m))
			// 捕獲する指し手に関しては簡易SEE + MVV/LVA
			m.value = (Value)Eval::CapturePieceValue[pos.piece_on(to_sq(m))]
			-Value(LVA(type_of(pos.moved_piece_before(m)))) + Value(1 << 28);
		else
			// 捕獲しない指し手に関してはhistoryの値の順番
			m.value = history[from_to(m)][c];
}
Esempio n. 4
0
void MovePicker::score<EVASIONS>() {
  // Try captures ordered by MVV/LVA, then non-captures ordered by stats heuristics
  const ButterflyHistory& history = pos.this_thread()->history;
  Color c = pos.side_to_move();

  for (auto& m : *this)
      if (pos.capture(m))
          m.value =  PieceValue[MG][pos.piece_on(to_sq(m))]
                   - Value(type_of(pos.moved_piece(m))) + (1 << 28);
      else
          m.value = history[c][from_to(m)];
}
Esempio n. 5
0
void MovePicker::score() {

  static_assert(Type == CAPTURES || Type == QUIETS || Type == EVASIONS, "Wrong type");

  for (auto& m : *this)
      if (Type == CAPTURES)
          m.value =  PieceValue[MG][pos.piece_on(to_sq(m))]
                   + Value((*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]);

      else if (Type == QUIETS)
          m.value =  (*mainHistory)[pos.side_to_move()][from_to(m)]
                   + (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
                   + (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
                   + (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];

      else // Type == EVASIONS
      {
          if (pos.capture(m))
              m.value =  PieceValue[MG][pos.piece_on(to_sq(m))]
                       - Value(type_of(pos.moved_piece(m)));
          else
              m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
      }
}
Esempio n. 6
0
void MovePicker::score<QUIETS>() {

  const ButterflyHistory& history = pos.this_thread()->history;

  const PieceToHistory& cmh = *(ss-1)->history;
  const PieceToHistory& fmh = *(ss-2)->history;
  const PieceToHistory& fm2 = *(ss-4)->history;

  Color c = pos.side_to_move();

  for (auto& m : *this)
      m.value =  cmh[pos.moved_piece(m)][to_sq(m)]
               + fmh[pos.moved_piece(m)][to_sq(m)]
               + fm2[pos.moved_piece(m)][to_sq(m)]
               + history[c][from_to(m)];
}
Esempio n. 7
0
void
DTKSolutionTransfer::transfer(const Variable & from_var, const Variable & to_var)
{
  libmesh_experimental();

  EquationSystems * from_es = &from_var.system()->get_equation_systems();
  EquationSystems * to_es = &to_var.system()->get_equation_systems();

  // Possibly make an Adapter for from_es
  if(adapters.find(from_es) == adapters.end())
    adapters[from_es] = new DTKAdapter(comm_default, *from_es);

  // Possibly make an Adapter for to_es
  if(adapters.find(to_es) == adapters.end())
    adapters[to_es] = new DTKAdapter(comm_default, *to_es);

  DTKAdapter * from_adapter = adapters[from_es];
  DTKAdapter * to_adapter = adapters[to_es];

  std::pair<EquationSystems *, EquationSystems *> from_to(from_es, to_es);

  // If we haven't created a map for this pair of EquationSystems yet, do it now
  if(dtk_maps.find(from_to) == dtk_maps.end())
  {
    libmesh_assert(from_es->get_mesh().mesh_dimension() == to_es->get_mesh().mesh_dimension());

    shared_domain_map_type * map = new shared_domain_map_type(comm_default, from_es->get_mesh().mesh_dimension(), true);
    dtk_maps[from_to] = map;

    // The tolerance here is for the "contains_point()" implementation in DTK.  Set a larger value for a looser tolerance...
    map->setup(from_adapter->get_mesh_manager(), to_adapter->get_target_coords(), 30*Teuchos::ScalarTraits<double>::eps());
  }

  DTKAdapter::RCP_Evaluator from_evaluator = from_adapter->get_variable_evaluator(from_var.name());
  Teuchos::RCP<DataTransferKit::FieldManager<DTKAdapter::FieldContainerType> > to_values = to_adapter->get_values_to_fill(to_var.name());

  dtk_maps[from_to]->apply(from_evaluator, to_values);

  if(dtk_maps[from_to]->getMissedTargetPoints().size())
    libMesh::out<<"Warning: Some points were missed in the transfer of "<<from_var.name()<<" to "<<to_var.name()<<"!"<<std::endl;

  to_adapter->update_variable_values(to_var.name());
}
Esempio n. 8
0
void MovePicker::score<QUIETS>()
{
	const ButterflyHistory& history = pos.this_thread()->history;

	const PieceToHistory& cmh = *(ss - 1)->history;
	const PieceToHistory& fmh = *(ss - 2)->history;
	const PieceToHistory& fm2 = *(ss - 4)->history;

	Color c = pos.side_to_move();

	for (auto& m : *this)
	{
		Piece mpc = pos.moved_piece_after(m);
		Square msq = to_sq(m);

		m.value = cmh[msq][mpc]
				+ fmh[msq][mpc]
				+ fm2[msq][mpc]
				+ history[from_to(m)][c];
	}
}