This file is indexed.

/usr/share/pyshared/pychess/Variants/asymmetricrandom.py is in pychess 0.10.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
# AsymmetricRandom Chess

import random

from pychess.Utils.const import *
from pychess.Utils.Board import Board

class AsymmetricRandomBoard(Board):
    variant = ASYMMETRICRANDOMCHESS

    def __init__ (self, setup=False):
        if setup is True:
            Board.__init__(self, setup=self.asymmetricrandom_start())
        else:
            Board.__init__(self, setup=setup)

    def asymmetricrandom_start(self):        
        white = random.sample(('r', 'n', 'b', 'q')*16, 7)
        white.append('k')        
        black = white[:]
        random.shuffle(white)
        random.shuffle(black)
        
        # balance the bishops (put them on equal numbers of dark and light squares)
        whitedarkbishops = 0
        whitelightbishops = 0
        for index, piece in enumerate(white):
            if piece == 'b':
                if index % 2 == 0:  # even numbered square on the A rank are dark
                    whitedarkbishops += 1
                else:
                    whitelightbishops += 1
        blackdarkbishops = 0
        blacklightbishops = 0
        blackbishoprandomindexstack = []
        for index, piece in enumerate(black):
            if piece == 'b':
                if index % 2 == 1:  # odd numbered squares on the H rank are dark
                    blackdarkbishops += 1
                else:
                    blacklightbishops += 1
                blackbishoprandomindexstack.append(index)
        random.shuffle(blackbishoprandomindexstack)
        class RandomEnumeratePieces:
            def __init__ (self, pieces):
                self.pieces = pieces[:]
                self.randomindexstack = range(8)
                random.shuffle(self.randomindexstack)
            def __iter__ (self):
                return self
            def next(self):
                if not self.randomindexstack:
                    raise StopIteration
                else:
                    randomindex = self.randomindexstack.pop()
                    return randomindex, self.pieces[randomindex]
        while (whitedarkbishops != blackdarkbishops) or \
              (whitelightbishops != blacklightbishops):
            bishopindex = blackbishoprandomindexstack.pop()
            for index, piece in RandomEnumeratePieces(black):
                if piece != 'b':
                    if ((blackdarkbishops > whitedarkbishops) and \
                        (bishopindex % 2 == 1) and (index % 2 == 0)):
                        black[bishopindex] = piece
                        black[index] = 'b'
                        blacklightbishops += 1
                        blackdarkbishops = blackdarkbishops > 0 and (blackdarkbishops-1) or 0
                        break
                    elif ((blacklightbishops > whitelightbishops) and \
                          (bishopindex % 2 == 0) and (index % 2 == 1)):
                        black[bishopindex] = piece
                        black[index] = 'b'
                        blackdarkbishops += 1
                        blacklightbishops = blacklightbishops > 0 and (blacklightbishops-1) or 0
                        break
                    
        tmp = ''.join(black) + '/pppppppp/8/8/8/8/PPPPPPPP/' + \
              ''.join(white).upper() + ' w - - 0 1'
        
        return tmp


class AsymmetricRandomChess:
    __desc__ = \
        _("FICS wild/4: http://www.freechess.org/Help/HelpFiles/wild.html\n" +
          "* Randomly chosen pieces (two queens or three rooks possible)\n" +
          "* Exactly one king of each color\n" +
          "* Pieces placed randomly behind the pawns, SUBJECT TO THE CONSTRAINT THAT THE BISHOPS ARE BALANCED\n" +
          "* No castling\n" +
          "* Black's arrangement DOES NOT mirrors white's")
    name = _("Asymmetric Random")
    cecp_name = "unknown"
    board = AsymmetricRandomBoard
    need_initial_board = True
    standard_rules = True
    variant_group = VARIANTS_SHUFFLE


if __name__ == '__main__':
    Board = AsymmetricRandomBoard(True)
    for i in range(10):
        print Board.asymmetricrandom_start()