Code to migrate:

var moves = []; for (var i = 0; i < availSpots.length; i++){ var move = {}; move.index = newBoard[availSpots[i]]; newBoard[availSpots[i]] = player; if (player == aiPlayer){ var result = minimax(newBoard, huPlayer); move.score = result.score; } else{ var result = minimax(newBoard, aiPlayer); move.score = result.score; } newBoard[availSpots[i]] = move.index; moves.push(move); 

I can't translate this all into C # code because of a bunch of var. For example, how can you translate code

 var moves = []; 

, if it is an array of objects with properties of the score (Although it may be something said wrong, the head already hurts from this suffering.

Closed due to the fact that the essence of the question is not clear to the participants of Igor , tym32167 , AK , 0xdb , LFC on March 7 at 4:22 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And if it was C ++, could they not be transferred because of a bunch of int / char / float? And if PHP, then because of $, so? - Mr. Brightside
  • I can comment on your minus, if you're curious. In general, if you look at the questions like "translate the code from language1 to language2" - it is always from three to ten minuses and a closed question (you were just lucky that the answer was given to the last fifth minus ... more often than not). Because there are almost always people who say that they do not know “that” programming language (and some of them also know “this”), the questions “make for me” are always minus, because few people like freeloaders. - AK
  • Now, if you showed a desire to understand, would show that you half the code themselves understood how to translate and you have specific questions - then it would be a more neutral attitude. Relatively speaking, the federal center is ready to give two rubles for every ruble invested by the region - but at least you can show that you are ready to do something. Sometimes, the answers are also minus, so that there are no people who want to help the losers / freeloaders, so generally speaking you not only let yourself be under the minuses, but potentially also help you. - AK

1 answer 1

On this piece of code, I personally can only make such comments.

  //создается динамический массив или вроде того //в C# здесь можно использовать var moves = new List<Move>(); var moves = []; //перебираем в цикле массив availSpots for (var i = 0; i < availSpots.length; i++){ //создаем объект //в C# здесь можно создать экземпляр var move = new Move(); var move = {}; //присвоение "посадочного места на борту" для move //в C# было что-то типа move.Index = _newBoard[availSpots[i]]; move.index = newBoard[availSpots[i]]; //занимаем "посадочное место на борту" экземпляром игрока newBoard[availSpots[i]] = player; //если игрок равен или является ботом (префикс ai указывает на это) if (player == aiPlayer){ //вычисляем (вероятно экземпляр какого-то класса) с пом. функции //в которую передается массив того кто на борту //и игрок-типа-человек, вероятно префикс 'hu' означает human,т.е человек var result = minimax(newBoard, huPlayer); //в C# было бы move.Score = result.Score; //сам score вероятно интовый move.score = result.score; } else{ //иначе вычисляем результат в сравнении с ботом var result = minimax(newBoard, aiPlayer); move.score = result.score; } //динамическая типизация, она такая...:) //тут вместо экземпляра игрока присваиваем индекс newBoard[availSpots[i]] = move.index; //на C# было бы moves.Add(move); moves.push(move); 
  • Thanks, with the help of this I understand how to do it. I do not understand why I scored so many minuses. I for example did not know how to replace var move = {} with C #, but everything turns out to be simple. Other people can also come in handy. - JediMan4ik
  • This is because requests for translations from one language to another are disliked here. And for good reason, by the way ... Because you need to try to understand the implemented algorithm in the source language, and then rewrite it into the target language, and not try to "translate" line by line. - Bulson