国际象棋乐趣#3:国际象棋骑士【难度:1级】:
答案1:
namespace myjinxin
{
using System;
public class Kata
{
public int ChessKnight(string cell)
{
int v = cell[0] - 96;
int h = cell[1] - 48;
int totalMoves = 0;
if (h + 2 <= 8)
{
if (v + 1 <= 8) totalMoves++;
if (v - 1 >= 1) totalMoves++;
}
if (h - 2 >= 1)
{
if (v + 1 <= 8) totalMoves++;
if (v - 1 >= 1) totalMoves++;
}
if (v + 2 <= 8)
{
if (h + 1 <= 8) totalMoves++;
if (h - 1 >= 1) totalMoves++;
}
if (v - 2 >= 1)
{
if (h + 1 <= 8) totalMoves++;
if (h - 1 >= 1) totalMoves++;
}
return totalMoves;
}
}
}
答案2:
namespace myjinxin
{
using System;
using System.Linq;
using System.Collections.Generic;
public class Kata
{
public int ChessKnight(string cell){
int x=cell[0]-96,y=cell[1]-48;
return new int[][]{
new int[]{
x-2,y-1},
new int[]{
x-2,y+1},
new int[]{
x-1,y-2},
new int[]{
x-1,y+2},
new int[]{
x+2,y-1},
new int[]{
x+2,y+1},
new int[]{
x+1,y-2},
new int[]{
x+1,y+2}}.Count(z=>z[0]>0&&z[1]>0&&z[0]<9&&z[1]<9);
}
}
}
答案3:
namespace myjinxin
{
using System;
public class Kata
{
public int ChessKnight(string cell){
int i=4;
if((cell[0]>=99&&cell