We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I think the real game always allow player to choose, so I create a random that make a same (x,y) will have many results that player 1 and 2 can win.
Did I wrong?
usingSystem.CodeDom.Compiler;usingSystem.Collections.Generic;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Diagnostics.CodeAnalysis;usingSystem.Globalization;usingSystem.IO;usingSystem.Linq;usingSystem.Reflection;usingSystem.Runtime.Serialization;usingSystem.Text.RegularExpressions;usingSystem.Text;usingSystem;classMove{publicintx;publicinty;publicMove(intx,inty){this.x=x;this.y=y;}}classResult{Move[]moves=newMove[4]{newMove(-2,1),newMove(-2,-1),newMove(1,-2),newMove(-1,-2)};stringwinner="";int[,]board=newint[15,15];publicstringChessboardGame(intx,inty){// SetUpBoard(x, y);returnPlayerMove("First",x,y);}voidSetUpBoard(intx,inty){for(inti=0;i<15;i++){for(intj=0;j<15;j++)board[i,j]=0;}board[x,y]=1;for(inti=0;i<15;i++){for(intj=0;j<15;j++){Console.Write(board[i,j]+" ");}Console.WriteLine();}Console.WriteLine();}boolCheckNextMove(intx,inty){if(x<0||y<0||x>15||y>15)returnfalse;elsereturntrue;}stringPlayerMove(stringplayer,intx,inty){ShuffleMoves();foreach(varmoveinmoves){if(CheckNextMove(x+move.x,y+move.y)){inti=x+move.x;intj=y+move.y;// Console.WriteLine("Player: " + player + " move to x: " + i + " y: " + j);// SetUpBoard(i, j);returnPlayerMove(Player(player),i,j);}}returnPlayer(player);}stringPlayer(stringplayer){returnplayer=="First"?"Second":"First";}voidShuffleMoves(){Randomrnd=newRandom();moves=moves.OrderBy(x=>rnd.Next()).ToArray();}}classSolution{publicstaticvoidMain(string[]args){TextWritertextWriter=newStreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"),true);intt=Convert.ToInt32(Console.ReadLine().Trim());for(inttItr=0;tItr<t;tItr++){string[]firstMultipleInput=Console.ReadLine().TrimEnd().Split(' ');intx=Convert.ToInt32(firstMultipleInput[0]);inty=Convert.ToInt32(firstMultipleInput[1]);Resultres=newResult();stringresult=res.ChessboardGame(x,y);textWriter.WriteLine(result);}textWriter.Flush();textWriter.Close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
A Chessboard Game
You are viewing a single comment's thread. Return to all comments →
I think the real game always allow player to choose, so I create a random that make a same (x,y) will have many results that player 1 and 2 can win. Did I wrong?