コード例 #1
0
        int GetNumberOfInversions()
        {
            List <Tile> tiles      = repository.GetAll();
            int         inversions = 0;


            for (int i = 0; i < tiles.Count; i++)
            {
                int current = tiles[i].Number;

                if (current == GameInfo.TilesCount)
                {
                    continue;
                }

                for (int j = i; j < tiles.Count; j++)
                {
                    if (tiles[i].Number != GameInfo.TilesCount)
                    {
                        if (current > tiles[j].Number)
                        {
                            inversions += 1;
                        }
                    }
                }
            }

            return(inversions);
        }